SHARING-AND-VISIBILITY-DESIGNER practice question 28 of 30

How should the Architect ensure that OBJECT-LEVEL SECURITY is enforce within a custom Visualforce application that was a standard Apex controller on the Lead object?

Full set: 212 questions
Answer options
A: Use the runAs() method to enforce user permissions in the Apex controller.
B: Use the Schema.DescribeSObjectResultisAccessible() method in the Apex controller.​
C: Use the {!$ObjectType.lead.accessible} expression within the Visualforce page. Correct answer
D: Use the "With Sharing" keyword when defining the Visualforce page.
Correct Answer:
C. Use the {!$ObjectType.lead.accessible} expression within the Visualforce page.
Explanation

Standard controllers in Visualforce automatically enforce object-level and field-level security. However, to prevent rendering errors or showing UI components that a user should not see, the Visualforce page itself should check for accessibility. The {!$ObjectType.lead.accessible} global variable is a direct and efficient way to check if the current user has at least read access to the Lead object before attempting to render related content. This ensures the UI respects the user's object-level security settings.

Why Incorrect

A. The runAs() method is used exclusively within Apex test classes to validate code behavior in different user contexts; it does not enforce permissions in production code.
B. The isAccessible() method is used in Apex, typically within custom controllers, to programmatically check permissions. It is not the standard way for a Visualforce page using a standard controller.
D. The "With Sharing" keyword is used to define an Apex class, forcing it to respect the user's record-level sharing. It is not a directive used on a Visualforce page.

References

1. Salesforce Developers Documentation, Visualforce Developer Guide, "$ObjectType" section. It states, "$ObjectType.ObjectName.accessible: Returns true if the user has read access to the object, and false otherwise."

2. Salesforce Developers Documentation, "Enforcing CRUD and FLS" page. It highlights using $ObjectType and $Schema.SObjectType global variables for checking object and field accessibility in Visualforce pages.

Scroll to Top