RecordTypeId of an object can be determined by using 2 different options:
For example we will find out the recordtypeId of "Renewal" recordtype of opportunity.
By Using Describe:
By using SOQL:
For example we will find out the recordtypeId of "Renewal" recordtype of opportunity.
By Using Describe:
Id renewalRecordTypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Renewal').getRecordTypeId();
Advantage: Saves on SOQL limits but uses a describe call.
Id renewalRecordTypeId =[select id from recordType where sobjectType='Opportunity' AND DeveloperName='Renewal'].Id;
Advantage of SOQL: If in future, someone change the name of recordtype, the code will work as it refers developername.
No comments:
Post a Comment