3

If do a query like [SELECT Opportunity.Name, Product2.Name FROM OpportunityLineItem FOR UPDATE], is the Opportunity and Product2 locked, or just the OpportunityLineItem? I'm trying to set a field on the opportunity based on all the related Products, and it would be nice to be able to lock the Opportunity even though I'm querying the OpportunityLineItems.

3

Yes. Any related records are locked too.

You can find this mentioned in the Locking Considerations section of the documentation.

When you perform a DML operation on one record, related records are locked in addition to the record in question. For more information, see the Record Locking Cheat Sheet

Refer to the locking cheat sheet which details out how related/parent records are impacted based on the operation being performed on child objects. That has some good information.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.