Exam Certified Platform Developer II All QuestionsBrowse all questions from this exam
Question 192

A company wants to run different logic based on an Opportunity’s record type.

Which code segment handles this request and follows best practices?

    Correct Answer: D

    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.

Discussion
Udayudyvk1818Option: D

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

UllrOption: D

D only Don't SOQL to RecordType

dasabhisek404Option: C

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

parth9927Option: C

C is also the correct answer because it can handle code dynamically. don't need to hard code record type name.

stan_maltaOption: D

Save SOQL where you can.