PDI · Question #163
A custom picklist field, Food_Preference__c, exist on a custom object. The picklist contains the following options: 'Vegan','Kosher','No Preference'. The developer must ensure a value is populated…
The correct answer is C. Mark the field as Required on the field definition. To ensure a custom picklist field always has a value when a record is created or updated, marking the field as 'Required' in its field definition is the most efficient and robust solution.
Question
A custom picklist field, Food_Preference__c, exist on a custom object. The picklist contains the following options: 'Vegan','Kosher','No Preference'. The developer must ensure a value is populated every time a record is created or updated. What is the most efficient way to ensure a value is selected every time a record is saved?
Options
- ASet "Use the first value in the list as the default value" as True.
- BSet a validation rule to enforce a value is selected.
- CMark the field as Required on the field definition.
- DMark the field as Required on the object's page layout.
How the community answered
(44 responses)- A5% (2)
- B2% (1)
- C91% (40)
- D2% (1)
Why each option
To ensure a custom picklist field always has a value when a record is created or updated, marking the field as 'Required' in its field definition is the most efficient and robust solution.
Setting the first value as default populates the field initially but does not prevent users or processes from clearing the value before saving, thus not guaranteeing a value is always present.
A validation rule could enforce the requirement but is less efficient and more complex to configure than simply marking the field as 'Required', which provides the same core functionality declaratively.
Marking a field as 'Required' in its field definition enforces that a value must be present upon record creation or update at the database level, ensuring data integrity across all entry points, including UI, API, and data imports.
Marking a field as 'Required' on a page layout only enforces the requirement when that specific layout is used, failing to ensure data integrity when records are created or updated via other layouts or non-UI methods.
Concept tested: Enforcing required fields in Salesforce.
Source: https://help.salesforce.com/s/articleView?id=sf.custom_field_attributes.htm&type=5
Topics
Community Discussion
No community discussion yet for this question.