PDI · Question #6
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…
The correct answer is B. Use Opportunity. SObjectType.getDescribe().getRecordTypelnfos() to get a list of record types. The developer needs to find the current user's default Opportunity record type programmatically to set default values before inserting records.
Question
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? ns
Options
- AQuery the Profile where the ID equals userInfo.getProfileID() and then use the
- BUse Opportunity. SObjectType.getDescribe().getRecordTypelnfos() to get a list of record types,
- CUse the Schema.userlnfo.Opportunity.getDefaultRecordType() method. < Create the opportunity
How the community answered
(43 responses)- A9% (4)
- B84% (36)
- C7% (3)
Why each option
The developer needs to find the current user's default Opportunity record type programmatically to set default values before inserting records.
Querying the Profile object and then attempting to infer the default record type is an overly complex and indirect approach; the `RecordTypeInfo` methods provide a direct and accurate way to retrieve this information.
To find the current user's default record type, a developer can use `Opportunity.SObjectType.getDescribe().getRecordTypeInfos()` to get a map of `RecordTypeInfo` objects and then iterate through them to find the one where `isDefaultRecordTypeMapping()` returns `true` for the current user's profile.
The `Schema.userlnfo.Opportunity.getDefaultRecordType()` method does not exist in Salesforce Apex; the correct approach involves using `SObjectType.getDescribe().getRecordTypeInfos()`.
Concept tested: Apex Schema methods for Record Type information
Source: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Schema_SObjectType.htm#apex_Schema_SObjectType_getDescribe
Topics
Community Discussion
No community discussion yet for this question.