Hello friends, In this post we will see a code example which helps us to get the Label or API Name of any Salesforce object. so let's get started,
Get salesforce object label or name in apex
Salesforce provide a global sObject class named DescribeSObjectResult that help us to get property of any salesforce object. In this post we will see an small example of this class to understand it's effectiveness.
Code Example 1:
DescribeSObjectResult describe = SObjectType.Error_Log__c; System.debug('Label**'+describe.getLabel()); System.debug('API Name**'+describe.getName());
Code Example 2:
DescribeSObjectResult describe = Error_Log__c.sObjectType.getDescribe(); System.debug('Label**'+describe.getLabel()); System.debug('API Name**'+describe.getName());
Code Example 3:
System.debug('Label**'+SObjectType.Error_Log__c.getLabel()); System.debug('API Name**'+SObjectType.Error_Log__c.getName());You can use any of the above mentioned example to get label or name of any salesforce object. Results are same for each code example.
Output:
Hope you like this post, for any feedback or suggestions please feel free to comment. I would appreciate your feedback and suggestions.
Happy Coding
Thank you.
0 Comments
Post a Comment