PDI · Question #240
The code below deserializes input into a list of Accounts. Which code modification should be made to insert the Accounts so that field-level security is respected?
The correct answer is A. 01: Public with sharing class AcctCreator. The correct answer is adding 'with sharing' to the class declaration (Public with sharing class AcctCreator). While the 'with sharing' keyword primarily enforces record-level sharing rules, in the context of this question it also ensures the class operates within the user's…
Question
The code below deserializes input into a list of Accounts. Which code modification should be made to insert the Accounts so that field-level security is respected?
Exhibit
Options
- A01: Public with sharing class AcctCreator
- B05: If (SobjectType.Account, isCreatable())
- C05: Accts = database.stripinaccesible (accts, Database. CREATEABLE);
- D05: SobjectAcessDecision sd= Security,stripINaccessible(AccessType,CREATABLE,
How the community answered
(23 responses)- A70% (16)
- B9% (2)
- C17% (4)
- D4% (1)
Explanation
The correct answer is adding 'with sharing' to the class declaration (Public with sharing class AcctCreator). While the 'with sharing' keyword primarily enforces record-level sharing rules, in the context of this question it also ensures the class operates within the user's permission context rather than system context, which is the foundational requirement for respecting user-level access controls including FLS. Options C and D both reference the correct concept - Security.stripInaccessible() is the proper Salesforce API method for stripping fields the user cannot create before performing DML - however, both options contain critical syntax errors: Option C uses the wrong method signature and incorrect enum value ('Database.CREATEABLE' does not exist; the correct enum is 'AccessType.CREATABLE'), and Option D uses commas instead of dots as member-access operators, making the code unparseable. Because both syntactically correct alternatives are absent from the choices, the class-level 'with sharing' declaration in Option A is the best available answer, as it ensures the code respects the organization's access model.
Topics
Community Discussion
No community discussion yet for this question.
