Section 4 · User Interface · 25% of exam
4.1 Record Access, CRUD, Field Security, and Secure Apex
Exam objective
Given a scenario, prevent user-interface and data-access vulnerabilities by enforcing record, object, and field permissions at the appropriate boundary.
Security has more than one layer
A secure Salesforce feature answers three separate questions: which records can a user access, which objects can they read or change, and which fields can they read or change? Record-level sharing controls access to particular records. Object permissions such as Read, Create, Edit, and Delete control actions on an object. Field-level security controls access to individual fields. Permission sets and profiles grant these capabilities, while sharing rules, role hierarchy, teams, and manual sharing can affect record visibility.
A user interface that hides an edit button does not prevent a user from invoking the underlying server method or API. Client-side checks improve usability, but server-side operations must enforce authorization. Consider a component that accepts a record ID from the browser: the user can change that ID. The Apex method must verify that the caller can act on the requested record, and it must only return allowed data. Treat inputs from browsers, Flow variables, and AI actions as untrusted until validated.
Sharing declarations and operation modes
Apex sharing keywords control record-level sharing behavior of a class. with sharing enforces sharing rules for record access; without sharing bypasses sharing rules in the class context; inherited sharing adopts the caller's sharing context where applicable. These keywords do not, on their own, enforce CRUD or field-level security. Object and field permissions require an appropriate operation mode or explicit checks.
Current Salesforce developer documentation describes a notable version change: starting with API version 67.0, Apex database operations default to user mode, enforcing the running user's object, field, and sharing permissions. Older API versions and explicit system-mode operations can behave differently; triggers always run in system mode. The Platform Developer exam guide states alignment to Summer '25, while current platform documentation describes later API versions. For exam scenarios, use the release baseline and API version named in the prompt. For real development, inspect the class version and operation access mode. A with sharing declaration alone does not solve every access requirement. For user-mode SOQL or DML, permission failures can be surfaced rather than silently returning unauthorized data. If the business operation legitimately requires elevated access, make the system-mode boundary intentional, limit the fields and records handled, and avoid returning more data than the user is entitled to receive. Security review should include the calling user's access, not only the developer's admin account.
Prefer platform data services when suitable
Lightning Data Service and the UI API provide standard record operations and respect platform sharing, CRUD, and field-level security. Use them when the component needs supported record forms, fields, or data operations. Apex is appropriate for custom server logic or data operations that the standard data services do not cover, but it places more responsibility on the developer to define the contract and enforce access.
A secure review asks: Can a user guess or substitute a record ID? Is every requested field necessary? Does the method return data to an unauthorized caller? Are dynamic query values bound? Is an exception message revealing sensitive detail? Could a Flow, Visualforce controller, or Agentforce action invoke this method in a different context?
Never rely on hiding a control or filtering records only in JavaScript. Enforce access on the server and test with a least-privileged user.
Extra concept: fail closed
When authorization cannot be confirmed, deny the sensitive operation and return a controlled error. Avoid fallback logic that switches to a more privileged mode just because a user-mode query failed. A deliberate access boundary is easier to test and safer to maintain.
Key takeaways
- Separate record sharing, object permissions, and field-level security; each protects a different boundary.
- Sharing declarations alone do not enforce CRUD or FLS; operation mode and API version matter.
- Prefer Lightning Data Service for supported record access, and test custom Apex with least-privileged users. Official references:
- Salesforce Certified Platform Developer Exam Guide: https://help.salesforce.com/s/articleView?id=005298965&language=en_US&type=1
- Apex security and sharing: https://developer.salesforce.com/docs/platform/apex-dev/references/apex-dev/apex-security-sharing-chapter.html
- Enforcing user mode: https://developer.salesforce.com/docs/platform/apex-dev/references/apex-dev/apex-classes-enforce-usermode.html
- Secure coding access controls: https://developer.salesforce.com/docs/platform/secure-coding/guide/secure-coding-access-control-protect-from-crud-fls-vulnerabilities.html
- Apex security for Lightning components: https://developer.salesforce.com/docs/platform/lwc/guide/apex-security
- Lightning Data Service: https://developer.salesforce.com/docs/platform/lwc/guide/data-ui-api.html
