Certified Platform Developer II Exam QuestionsBrowse all questions from this exam

Certified Platform Developer II 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?

Show Answer
Correct Answer: AD

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

5 comments
Sign in to comment
Udayudyvk1818Option: D
Aug 5, 2023

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
Mar 28, 2023

D only Don't SOQL to RecordType

stan_maltaOption: D
Nov 12, 2023

Save SOQL where you can.

parth9927Option: C
May 19, 2024

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

dasabhisek404Option: C
Jul 6, 2024

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