You need to sign in to do that
Don't have an account?

Get Field Description in Apex Code
Hi,
Is there any way to get description of all fields of an object in apex code?
Able to query inline text help, label, api name, length etc, but not the description.
Any workaround/trick ?
Thanks
Sid
Is there any way to get description of all fields of an object in apex code?
Able to query inline text help, label, api name, length etc, but not the description.
Any workaround/trick ?
Thanks
Sid
You have to use the describe calls to get all the details of a field.
See the links below,
Is there anyway to get the name/label of a field without doing a field describe?
http://salesforce.stackexchange.com/questions/32436/is-there-anyway-to-get-the-name-label-of-a-field-without-doing-a-field-describe
getting Value of a field by its Name in apex salesforce
http://stackoverflow.com/questions/15114586/getting-value-of-a-field-by-its-name-in-apex-salesforce
Regards,
Ashish
A trick (and a very difficult one) is to use the Metadata API. You can do this via APEX - but the process is async. Since you want to fetch the information, it would require "retrieve" calls - and those are seriously difficult to do in APEX.
http://andyinthecloud.com/2013/10/27/introduction-to-calling-the-metadata-api-from-apex/
http://www.salesforce.com/us/developer/docs/api_meta/api_meta.pdf
The Idea: Object/Field Description text available to API and APEX Describe call , please vote for the same.
https://success.salesforce.com/ideaView?id=08730000000gO3LAAU
Also See the blog: Getting Salesforce Field Metadata the Easy Way
http://blog.jeffdouglas.com/2011/10/20/getting-salesforce-field-metadata-the-easy-way/
Regards,
Ashish
But not sure how to GET and DISPLAY that excel file in VF Page. Any ideas ?
public class SObjectMetadata {
public String fieldName {get;set;}
public Schema.DisplayType fieldType {get;set;}
public String sObjectName {get;set;}
public SObjectMetadata(String pFieldName, Schema.DisplayType pFieldType, String pSobjectName) {
this.fieldName = pFieldName;
this.fieldType = pFieldType;
this.sObjectName = pSobjectName;
}
}
@AuraEnabled
public static String getsObjectMetadata(String pSobject) {
List<SObjectMetadata> sObjectMetadataList = new List<SObjectMetadata>();
Map<String, Schema.SObjectField> fieldMap = Schema.getGlobalDescribe().get(pSobject).getDescribe().fields.getMap();
for(Schema.SObjectField ft : fieldMap.values()) {
Schema.DescribeFieldResult fd = ft.getDescribe();
sObjectMetadataList.add(new SObjectMetadata(fd.getName(), fd.getType(), pSobject));
}
return JSON.serialize(sObjectMetadataList);
}
Select Label, QualifiedApiName, Description from FieldDefinition Where EntityDefinition.QualifiedApiName='Account'
Where EntityDefinition.QualifiedApiName is the api name of the object you're interested in. Then, to run this query in Apex and get the results, you can establish an Http connection and send the query to the tooling api like so:
req.setEndpoint(instanceName + '/services/data/v48.0/tooling/query/?q=Select+EntityDefinition.DurableId,Label,DeveloperName,DurableId,QualifiedApiName,DataType,Description+from+FieldDefinition+Where+EntityDefinition.QualifiedApiName=\'' + selectedObject + '\'');
Again selectedObject would be your object's API name. Then you can deserialize the Json response of the query and access the data. For a full example of this check out Salesforce Field Auditor (https://github.com/CompassionIntl/SalesforceSchemaAuditor/blob/master/classes/FieldAuditor.cls)