PDI · Question #123
Given the following code snippet, that is part of a custom controller for a Visualforce page: In which two ways can the try/catch be enclosed to enforce object and field-level permissions and…
The correct answer is A. Use if (Schema, sobjectType, Contact, isUpdatable ( ) ) B. Use if (Schema , sobjectType. Contact. Field, Is_Active_c. is Updateable ( ) ). To ensure DML operations respect object-level and field-level security, Apex code should explicitly check for update permissions before execution.
Question
Given the following code snippet, that is part of a custom controller for a Visualforce page:
In which two ways can the try/catch be enclosed to enforce object and field-level permissions and prevent the DML statement from being executed if the current logged-in user does not have the appropriate level of access? Choose 2 answers
Exhibit
Options
- AUse if (Schema, sobjectType, Contact, isUpdatable ( ) )
- BUse if (Schema , sobjectType. Contact. Field, Is_Active_c. is Updateable ( ) )
- CUse if (Schema.sObjectType.Contact.isAccessible ( ) )
- DUse if (thisContact.Owner = = UserInfo.getuserId ( ) )
How the community answered
(39 responses)- A77% (30)
- C15% (6)
- D8% (3)
Why each option
To ensure DML operations respect object-level and field-level security, Apex code should explicitly check for update permissions before execution.
`Schema.sObjectType.Contact.isUpdateable()` checks if the current user has object-level permissions to update records of the Contact object, preventing unauthorized DML.
`Schema.sObjectType.Contact.fields.Is_Active_c.isUpdateable()` checks if the current user has field-level permissions to update the specific 'Is_Active_c' field on the Contact object.
`Schema.sObjectType.Contact.isAccessible()` checks for read access, which is not sufficient for enforcing update permissions required for DML operations.
`thisContact.Owner == UserInfo.getUserId()` checks record ownership, which is a business logic condition, but it does not enforce object or field-level security permissions.
Concept tested: Enforcing object and field level security in Apex
Source: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_perms_enforcing.htm
Topics
Community Discussion
No community discussion yet for this question.
