You need to sign in to do that
Don't have an account?

Best way to retrieve recordtypes
Hi All,
What is the best way to write the code to retrieve the record type?
Below are the two ways
1. ID rtId = [SELECT Id FROM RecordType WHERE sObjectType='Opportunity' AND Name='RT1'].Id;
2. Id rtId = Schema.SObjectType.Opportunity.getRecordTypeInfosByDeveloperName().get('RT1').getRecordTypeId();
Thanks!
What is the best way to write the code to retrieve the record type?
Below are the two ways
1. ID rtId = [SELECT Id FROM RecordType WHERE sObjectType='Opportunity' AND Name='RT1'].Id;
2. Id rtId = Schema.SObjectType.Opportunity.getRecordTypeInfosByDeveloperName().get('RT1').getRecordTypeId();
Thanks!
I would suggest the second option i'e below.
Because it does not require any SOQL query for retrival which will be efficient way .
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,
All Answers
I would suggest the second option i'e below.
Because it does not require any SOQL query for retrival which will be efficient way .
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,
As per salesforce best practice we should follow second point. because 2nd point we don't need SOQL to fetch recordType that's will help tp breach the governer limit of SOQL that's fix 100.
To get a recordTypeId dynamically based on the developername of recordtype i.e API Name of RecordType
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh