Get Key Prefix of Object in Salesforce

Using Apex:

You can use DescribeSObjectResult() method to get Custom and Standard Object prefix in apex class.

For ex: 

Lets say we have a custom object "Group_Task__c", and instead of hardcoding Object Id we want to make it dynamic.

  • Schema.DescribeSObjectResult result = Group_Task__c.SObjectType.getDescribe();
  • PageReference pageRef = new PageReference('/' + result.getKeyPrefix());
  • pageRef.setRedirect(true);
  • return pageRef;

Using Workbench:

Log into workbench-> go to Info > Standard & Custom Objects and pick an object from the pick list.

Comments

Popular posts from this blog

List of Key Prefixes in Salesforce

SFDX Install CPQ in Scratch org