Exam PDII Topic 4 Question 69 Discussion
Actual exam question for Salesforce's PDII exam
Question #: 69
Topic #: 4
Question #: 69
Topic #: 4
Refer to the code snippet below:

A custom object called Credit_Memo__c exists in a Salesforce environment. As part of a new feature development that retrieves and manipulates this type of record, the developer needs to ensure race conditions are prevented when a set of records are modified within an Apex transaction.
In the preceding Apex code, how can the developer alter the query statement to use SOQL features to prevent race conditions within a transaction?

A custom object called Credit_Memo__c exists in a Salesforce environment. As part of a new feature development that retrieves and manipulates this type of record, the developer needs to ensure race conditions are prevented when a set of records are modified within an Apex transaction.
In the preceding Apex code, how can the developer alter the query statement to use SOQL features to prevent race conditions within a transaction?
Suggested Answer: A Vote an answer
To prevent race conditions during an Apex transaction, the SOQL query can be modified to include the "FOR UPDATE" keyword. This keyword locks the records that are returned by the query, preventing other transactions from modifying them until the current transaction is complete. This ensures that the retrieved records cannot be changed by another process before the current transaction is completed, thus preventing race conditions. The correct option to use in the code snippet provided is:
[SELECT Id, Name, Amount__c FROM Credit_Memo__c WHERE Customer_Id__c = :customerId LIMIT 50 FOR UPDATE] This will lock up to 50 records of Credit_Memo__c with the specified Customer_Id__c for the duration of the transaction.
References:
FOR UPDATE
Preventing Record Update Conflicts
[SELECT Id, Name, Amount__c FROM Credit_Memo__c WHERE Customer_Id__c = :customerId LIMIT 50 FOR UPDATE] This will lock up to 50 records of Credit_Memo__c with the specified Customer_Id__c for the duration of the transaction.
References:
FOR UPDATE
Preventing Record Update Conflicts
by Shirley at Aug 20, 2026, 11:22 PM
0
0
0
10
Comments
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
Report Comment
Commenting
You can sign-up / login (it's free).