Example: Retrieve Field Descriptions


Example: Retrieve Field Descriptions


This code example shows how to retrieve field description information using the Salesforce metadata API.

 Drop Table MD_FieldDesc
 go

 CREATE TABLE MD_FieldDesc (
 [Name] [nvarchar](255) NULL,
 [Member] [nvarchar](255) NULL,
 [MetadataXML] [xml] NULL,
 [CreatedByWildcard] [bit] NULL,
 [CreatedByList] [bit] NULL,
 [Error] [nvarchar](255) NULL,
 [ID] [nchar](18) NULL
 )

 INSERT INTO MD_FieldDesc (Name,Member) Values ( 'CustomObject', '*')

 -- Get a list of objects with customer fields
 EXEC SF_Metadata 'List', 'Salesforce', 'MD_FieldDesc'

 -- Cleanup wildcard and objects that will error
 DELETE MD_FieldDesc WHERE Member = '*'
 DELETE MD_FieldDesc WHERE Member = 'SiteChangeList'

 -- Retrieve the field metadata
 EXEC SF_Metadata 'Retrieve', 'Salesforce', 'MD_FieldDesc'

 -- Query to select descriptions
 ;WITH XMLNAMESPACES(DEFAULT 'http://soap.sforce.com/2006/04/metadata') SELECT Member
 ,fn.c.value('(fullName)[1]','nvarchar(50)') as FieldName
 ,fn.c.value('(description)[1]','nvarchar(50)') as Description
 ,fn.c.value('(../fullName)[1]','nvarchar(50)') as PicklistValue
 ,fn.c.value('(.)[1]','nvarchar(50)') as ControllingPicklistValue FROM MD_FieldDesc
 cross apply metadataxml.nodes ('/CustomObject/fields') as fn(c)