PD1 Process Automation & Logic 2 — Questions and Answers
Question 1: A developer needs to prevent a Trigger from recursively firing. What is the recommended approach?
- Use a static Boolean variable in a handler class to track if the trigger has already run (Correct answer)
- Add a recursive flag field to the sObject record
- Use a platform event to defer processing
- Set the trigger context variable isBefore to false
Correct answer: Use a static Boolean variable in a handler class to track if the trigger has already run
A static Boolean variable persists for the duration of a transaction, allowing triggers to check and set a flag to prevent re-entry.
Question 2: Which order of execution step occurs BEFORE Apex triggers fire on a record update?
- Workflow rules
- System validation rules (Correct answer)
- Process Builder flows
- Assignment rules
Correct answer: System validation rules
Salesforce runs system validation rules before before-triggers in the order of execution.
Question 3: In a before-insert trigger, a developer sets a field value on Trigger.new records. What additional DML operation is required?
- An explicit update DML call
- An explicit insert DML call
- No additional DML; changes to Trigger.new are saved automatically (Correct answer)
- A Database.update() call with allOrNothing set to false
Correct answer: No additional DML; changes to Trigger.new are saved automatically
In before triggers, modifications to Trigger.new records are saved automatically without requiring a separate DML statement.
Question 4: A Flow built in Flow Builder needs to update a related Account when an Opportunity is closed. Which element should the developer use?
- Get Records element followed by an Update Records element (Correct answer)
- Assignment element followed by a Loop element
- Decision element only
- Subflow element calling an autolaunched flow on Account
Correct answer: Get Records element followed by an Update Records element
A Get Records element retrieves the related Account, and an Update Records element applies changes to it.
Question 5: What does the `with sharing` keyword enforce in an Apex class?
- Object-level security based on profiles
- Record-level sharing rules for the running user (Correct answer)
- Field-level security on all SOQL queries
- System-mode access ignoring all security
Correct answer: Record-level sharing rules for the running user
`with sharing` enforces the running user's record-level sharing rules, preventing access to records they do not have permission to see.
Question 6: A developer wants a scheduled Apex job to run every day at midnight. Which interface must the Apex class implement?
- Queueable
- Batchable
- Schedulable (Correct answer)
- Callable
Correct answer: Schedulable
The `Schedulable` interface allows an Apex class to be scheduled via the UI or System.schedule() to run at specified times.
Question 7: When bulkifying a trigger, a developer uses a Set to collect record IDs before a SOQL query. What is the primary benefit?
- It sorts IDs in ascending order before querying
- It eliminates duplicate IDs so only one query is needed for all records in the trigger batch (Correct answer)
- It converts IDs to strings for dynamic SOQL
- It caches results to avoid hitting governor limits on subsequent transactions
Correct answer: It eliminates duplicate IDs so only one query is needed for all records in the trigger batch
A Set automatically deduplicates IDs, ensuring a single efficient SOQL query handles all records in a bulk trigger invocation.
A developer needs to prevent a Trigger from recursively firing.
What is the recommended approach?