Sunday, January 10, 2016

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

No comments:

Post a Comment