+ Start a Discussion
Harinder MaanHarinder Maan 

why we use getDescribe() in salesforce

Ishwar ShindeIshwar Shinde
Hi Harinder,

We use it to get meta data of sobject. 

To access the describe result for an sObject, use one of the following methods:
1. Call the getDescribe method on an sObject token.
2. Use the Schema sObjectType static variable with the name of the sObject. For example, Schema.sObjectType.Lead.

Schema.DescribeSObjectResult is the data type for an sObject describe result.

The following example uses the getDescribe method on an sObject token:
1Schema.DescribeSObjectResult dsr = Account.sObjectType.getDescribe();

The following example uses the Schema sObjectType static member variable:
1Schema.DescribeSObjectResult dsr = Schema.SObjectType.Account;

More details can be found on - https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dynamic_describe_objects_understanding.htm
Harsh Aditya 21Harsh Aditya 21
Hi Harinder,

getDescribe() is used to to get the details of the field like the name of the field  (API name), type of the field , length of the field etc, 
you  can get the details and use it for comparing, firing different events and action based on the requirement in Apex.

For more details, refer : http://blog.jeffdouglas.com/2011/10/20/getting-salesforce-field-metadata-the-easy-way/

Harsh Aditya.
Vasani ParthVasani Parth

You can describe sObjects either by using tokens or the describeSObjects Schema method. You can get more info here (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dynamic_describe_objects_understanding.htm)
Amit Chaudhary 8Amit Chaudhary 8
Please check below post to see describe call
1) http://amitsalesforce.blogspot.com/search/label/Apex%20Describe

When to use
Example 1:-

Some time in code we need to get recordTypeId . For that generally we used SOQL like below :-
Id contRecordTypeId = [Select id from RecordType where sObjectType = 'Contact' and developerName ='NameOfRecordType' ].id ;
You can try below Describe to get record Type Id without SOQL
Id contRecordTypeId = Schema.SObjectType.Contact.getRecordTypeInfosByName().get('NameOfRecordType').getRecordTypeId();

Example 2:-

If you want to get the Prefix of any object . Please try below code.
String keyPrefix = Account.sObjectType.getDescribe().getKeyPrefix();
System.debug('PREFIX--' + keyPrefix );
Example 3:-
Apex Describe | Dynamic retrieval of object label & field label

Please let us know if this will help you

Amit Chaudhary