Wednesday 16 December 2015

How to get RecordTypeId without SOQL | Get RecordTypeId by Describe Call



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();


Thanks
Amit Chaudhary

No comments:

Post a Comment