Apr 19, 2021

ReUsable Schema Snippets


          Get Object from Record Id:

Id  recordId = '100xxxxxxxxxxxxabc';

Schema.DescribeSObjectResult objectDescribe = recordId.getSobjectType().getDescribe();

String objectName = objectDescribe.getName();


Get Record Type Id Dynamically


          Get Record Type Id by  Record Type Label:

String recordTypeLabel='Parent Account';

String ObjectAPI='Account';

String accRecordTypeID =
Schema.getGlobalDescribe().get(ObjectAPI).getDescribe().getRecordTypeInfosByName().
get(recordTypeLabel).getRecordTypeId();


       Get Record Type Id by  Record Type Developer Name:

String recordTypeDeveloperName='Parent_Account';

String ObjectAPI='Account';

String accRecordTypeID =
Schema.getGlobalDescribe().get(ObjectAPI).getDescribe().getRecordTypeInfosByDeveloperName().get(recordTypeDeveloperName).getRecordTypeId();

 


Get Field Type Dynamically

 

GET Field Type Dynamically 

String objectAPIName = 'Account';
String fieldAPIName = 'Name';

SObjectType r = ( (SObject) Type.forName('Schema.'+objectAPIName).newInstance())).
getSObjectType();

 DescribeSObjectResult d = r.getDescribe();

System.debug(d.fields.getMap().get(fieldAPIName).getDescribe().getType());

 


No comments:

Post a Comment