A company wants to run different logic based on an Opportunity’s record type.
Which code segment handles this request and follows best practices?
A company wants to run different logic based on an Opportunity’s record type.
Which code segment handles this request and follows best practices?
Option D is the correct choice because it uses the `Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get()` method, which avoids using SOQL queries to obtain record type information. This approach is more efficient as it saves SOQL queries and adheres to best practices by directly retrieving the Record Type Ids from the schema. Using SOQL for fetching Record Type IDs, like in options A and C, is less efficient and should be avoided if possible. Option B hardcodes the Record Type IDs, which is not recommended as it reduces code flexibility and maintainability.
answer should be D. to simply use getRecordTypeInfosByDeveloperName https://salesforce.stackexchange.com/questions/11968/what-would-be-the-best-approach-to-get-the-recordtype-id
D only Don't SOQL to RecordType
Option D is given wrong. It was- Id recType_New = Schema.SObjectType.Opportunity.getRecordTypeInfosByDeveloperName().get('New').getRecordType.Id(); Id recType_Renewal = Schema.SObjectType.Opportunity.getRecordTypeInfosByDeveloperName().get('Renewal').getRecordType.Id(); In that case C is right
C is also the correct answer because it can handle code dynamically. don't need to hard code record type name.
Save SOQL where you can.