3

Can anyone clearly explain what exact use of DescribeFieldResult Class in Apex code. And also please provide an example.

1 Answer 1

3

The DescribeFieldResult Class contains methods which provide you the metadata info about a field on a sObject from which you have fetched the DescribeFieldResult instance:

For example:

Schema.DescribeFieldResult fieldResult =
                                  Schema.SObjectType.Custom_Object__c.fields.Status__c;

If you have a close look at the documentation of DescribeFieldResult class available in the Salesforce docs, you will see that you get the length of the field, if its a formula field then you can even get the formula within that field, the default value etc.

There could be multiple use cases wherein you would need such information:

One sample use case might be to create a Select * from... SQL equivalent in SOQL. This is explained very well in a blog here.

Another use case would be to fetch the metadata from each of the fields of the object and compare it with another to figure out the difference (ex: record or object metadata comparison in sandbox vs prod) This Chrome extension relies heavily on such metadata returned by the DescribeFieldResult class and shows you the difference between two records/objects and their metadata.

Hope this helps.

5
  • In a object I have created a picklist feild ,but the pick list values are stored in translation settings can i get those values using these methods
    – user18601
    Apr 11, 2015 at 9:58
  • And also explain schema class what is use in sales force ?
    – user18601
    Apr 11, 2015 at 10:04
  • for translation settings i guess metadata api is the only option salesforce.com/us/developer/docs/api_meta/Content/… Apr 11, 2015 at 10:10
  • The schema class is used to get the metadata of your entire salesforce org, imagine accessing any object, any fields on those objects, extracting datatype info, tabs etc. Apr 11, 2015 at 10:13
  • I just found this "Use toLabel(fields) to translate SOQL query results into the user’s language" see if you can use this to get the translated piclist values salesforce.com/us/developer/docs/soql_sosl/Content/… Apr 11, 2015 at 18:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .