Universal Containers implemented a private sharing model for the Account object. A custom Account search tool was developed with Apex to help sales representatives find accounts that match multiple criteria they specify. Since its release, users of the tool report they can see Accounts they do not own. What should the developer use to enforce sharing permission for the currently logged-in user while using the custom search tool?
Correct Answer: D
The with sharing keyword on the class declaration enforces the sharing rules that apply to the current user. This means that the user can only see and modify the records that they have access to based on the organization-wide defaults, role hierarchy, sharing rules, manual sharing, teams, and territories. The without sharing keyword, on the other hand, ignores the sharing rules and allows the user to access all records, regardless of ownership or sharing settings. This can pose a security risk and should be used with caution. The schema describe calls and the UserInfo Apex class do not directly affect the sharing rules, but rather provide information about the object and field permissions, and the user's profile and role, respectively. These can be used to check the user's access level, but not to enforce the sharing rules on the custom search tool. References: * Apex Developer Guide: Using the with sharing, without sharing, and inherited sharing Keywords, pages 13-14 * Trailhead: Platform Developer I Certification Study Guide: Apex Basics and Database, unit 3
Question 82
(Full question statement) Which statement generates a list ofLeadsandContactsthat have a field containing the phrase "ACME"?
Correct Answer: C
Comprehensive and Detailed Explanation From Exact Extract: C (Correct):This is the correctSOSL (Salesforce Object Search Language)syntax. It performs a full-text search across multiple objects and fields. The format FIND '*ACME*' IN ALL FIELDS RETURNING Contact, Lead is thestandard and correctapproach for cross-object keyword searches. Incorrect options: A:Incorrect syntax; needs ALL FIELDS or NAME FIELDS, and proper result typing. B:SOQL does not support searching across multiple objects in a single query. D:Incorrect casing and structure; missing proper list handling. Reference:Apex Developer Guide - SOSL Syntax This relates toDeveloper Fundamentals (23%), specificallySOSL vs. SOQL use cases and syntax.
Question 83
While developing an Apex class with custom search functionality that will be launched from a Lightning Web Component, how can the developer ensure only records accessible to the currently logged in user are displayed?
Correct Answer: C
To ensure that only records accessible to the currently logged-in user are displayed when developing an Apex class for custom search functionality launched from a Lightning Web Component (LWC), the developer should use the with sharing keyword. with sharing Keyword: This keyword enforces the sharing rules of the current user, ensuring that the Apex class respects the user's record-level access permissions. When an Apex class is declared with with sharing, it enforces sharing rules, meaning users can only access records they have permission to see. "Use the with sharing keyword when declaring a class to enforce the sharing rules that apply to the current user." - Apex Developer Guide: Using the with sharing or without sharing Keywords Importance in LWCs: Lightning Web Components invoke Apex methods annotated with @AuraEnabled, which execute in system context by default. Without specifying sharing, these methods can access all records, potentially exposing data that the user shouldn't see. "By default, Apex code runs in system context; that is, the current user's permissions and field-level security do not apply." - Apex Developer Guide: Enforcing Sharing Rules Why Not inherited sharing: While inherited sharing allows an Apex class to run in the sharing context of the caller, in this scenario, since the LWC does not have an inherent sharing context, using with sharing explicitly ensures sharing rules are enforced. WITH SECURITY_ENFORCED Clause: This SOQL clause enforces field-level security (FLS) and object-level security (OLS), not record-level sharing rules. Therefore, it does not restrict records based on the user's sharing settings. "The WITH SECURITY_ENFORCED clause applies object-level and field-level security checks to SOQL queries to ensure that users don't see fields or objects they don't have access to." - SOQL and SOSL Reference: WITH SECURITY_ENFORCED Clause Conclusion: By declaring the Apex class with with sharing, the developer ensures that only records the user has access to are returned, aligning with the requirement.
Question 84
A developer writes a trigger on the Account object on the before update event that increments a count field. A workflow rule also increments the count field every time that an Account is created or update. The field update in the workflow rule is configured to not re-evaluate workflow rules. What is the value of the count field if an Account is inserted with an initial value of zero, assuming no other automation logic is implemented on the Account?
Correct Answer: D
Question 85
A developer executes the following query in Apex to retrieve a list of contacts for each account: List<account> accounts = [Select ID, Name, (Select ID, Name from Contacts) from Account] ; Which two exceptions may occur when it executes? (Choose two.)