Salesforce Platform Developer I (legacy) — Question 165
A developer is creating a page that allows users to create multiple Opportunities. The developer is asked to verify the current user’s default Opportunity record type, and set certain default values based on the record type before inserting the record.
How can the developer find the current user’s default record type?
Answer options
- A. Use the Schema.userInfo.Opportunity.getDefaultRecordType() method.
- B. Query the Profile where the ID equals userInfo.getProfileID() and then use the profile.Opportunity.getDefaultRecordType() method.
- C. Create the opportunity and check the opportunity.recordType, which will have the record ID of the current user’s default record type, before inserting.
- D. Use Opportunity.SObjectType.getDescribe().getRecordTypeInfos() to get a list of record types, and iterate through them until isDefaultRecordTypeMapping() is true.
Correct answer: D
Explanation
The correct answer is D because it directly retrieves all record types associated with the Opportunity object and checks which one is set as the default for the current user. Option A is incorrect as that method does not exist. Option B misuses the profile method, as it does not directly provide the default record type. Option C is also incorrect since checking the record type after creation does not help in determining the default record type beforehand.