Salesforce-Platform-Developer-II Practice Test
202 Questions
Universal Containers uses Salesforce to track orders in an order__c object. The order = object has private organization-wide defaults. The order = object has a custom field, Quality_Controller_c, that is a Lookup to User and is used to indicate that the specified User is performing quality control on the order_ co. What should be used to automatically give read only access to the User set in the Quality_Controller field?
A. Record ownership
B. Criteria-based sharing
C. Apex managed sharing
D. User managed sharing
Explanation:
To address the requirement of automatically granting read-only access to the user specified in the Quality_Controller__c field on the order__c object, we need to consider the Salesforce sharing model and the tools available. The order__c object has private organization-wide defaults, meaning records are only accessible to the record owner and users with higher roles in the hierarchy (if enabled), unless additional sharing is configured. The Quality_Controller__c field is a Lookup to the User object, identifying the individual responsible for quality control, and this user needs automatic read-only access to the corresponding order record.
Let’s evaluate the provided options:
A. Record Ownership
Record ownership in Salesforce assigns a user as the owner of a record, granting them full access by default (e.g., read, edit, delete, and sharing capabilities, depending on their profile and role). The requirement, however, specifies read-only access for the user in the Quality_Controller__c field, not full control. Additionally, ownership is typically a single user assigned to the record, not a mechanism to grant access based on a separate lookup field. Making the Quality_Controller__c user the owner would both exceed the required access level and fail to align with the intent of indicating a quality control role rather than ownership. Thus, record ownership is not suitable.
B. Criteria-Based Sharing
Criteria-based sharing rules in Salesforce allow records to be shared with users, roles, or groups based on field values or record ownership. For example, we could create a rule like "Share order__c records where Quality_Controller__c is not null," but the challenge lies in specifying who to share with. Criteria-based sharing typically shares records with predefined recipients, such as a role, group, or all internal users, not dynamically with the specific user referenced in a lookup field like Quality_Controller__c. While we can use criteria to identify which records to share (e.g., based on the presence of a value in Quality_Controller__c), Salesforce’s declarative sharing rules do not support dynamically targeting the user specified in that field as the recipient. This limitation makes criteria-based sharing insufficient for automatically granting access to the exact user in the lookup field.
C. Apex Managed Sharing
Apex managed sharing allows programmatic control over record access by creating sharing records via Apex code. In this scenario, we can use an Apex trigger on the order__c object to detect changes to the Quality_Controller__c field (on insert or update) and create a corresponding order__Share record. This sharing record would specify:
✔ ParentId: The ID of the order__c record.
✔ UserOrGroupId: The ID of the user in the Quality_Controller__c field.
✔ AccessLevel: Set to "Read" for read-only access.
✔ RowCause: A custom sharing reason (e.g., "Quality_Control__c") to track the purpose of the share.
For example, a basic trigger might look like this:
This approach automates the process: whenever the Quality_Controller__c field is populated or updated, the trigger ensures the specified user gains read-only access. It also allows for cleanup logic (e.g., deleting old sharing records if the field changes or is cleared), ensuring access remains aligned with the field value. Given the need for dynamic, field-specific sharing, Apex managed sharing is a viable and appropriate solution.
D. User Managed Sharing
User managed sharing, also known as manual sharing, allows users with sufficient permissions (e.g., "Manage Sharing" on their profile) to manually share a record with other users or groups, specifying the access level (e.g., read-only). However, this process requires human intervention for each record, either by the record owner or an administrator. The requirement emphasizes automatic access, which manual sharing cannot provide, as it depends on someone explicitly sharing the record each time the Quality_Controller__c field is set or changed. This makes user managed sharing impractical due to its lack of automation and potential for inconsistency.
Conclusion:
The goal is to automatically grant read-only access to the user in the Quality_Controller__c field. Record ownership (A) provides too much access and isn’t field-driven. Criteria-based sharing (B) cannot dynamically target the user in a lookup field. User managed sharing (D) is manual, not automatic. Apex managed sharing (C), however, offers the flexibility to programmatically create sharing records based on the Quality_Controller__c field value, meeting both the automation and access-level requirements. While declarative solutions like Flow or Process Builder might seem appealing, they cannot directly create sharing records, leaving Apex as the most effective approach for this custom object scenario.
Thus, the best solution is C. Apex managed sharing.
Salesforce-Platform-Developer-II Practice-Test - Home | Previous |
Page 8 out of 202 Pages |