0

I am assigned a POC project to consciously attempt a record and its children from one block of code and the other block of code would try to see how an update on such locked records behave.

I am fine selecting a parent record for update, but figured out that FOR Update cannot be used in subquery, so i tried:

for(List<Opportunity> accList : [Select account.website from Opportunity where id='abcdefghijklmnop' For Update])

but it is not locking the account record, it is just locking the Opportunity.

Any ideas?

3
  • I am not able to understand your scenario completely, Which Object you are trying to update? Why you put List<Opportunity> accList ?
    – Subhash
    Commented Jun 6, 2016 at 7:00
  • I want to lock Opportunity & Account records, so basically parent and child records.
    – SF Learner
    Commented Jun 6, 2016 at 7:01
  • 1
    I think you will need 2 queries for this, unfortunately. Commented Jun 6, 2016 at 7:45

1 Answer 1

1

When you lock Opportunity, because the two are in a M-D relationship, the Account should automatically get locked. There's shouldn't be a need to lock both separately. If you're not seeing that behavior, you'll need to lock both of them separately. Be certain to select AccountId as part of your query which may solve your issue.

1
  • Thanks all, i am going to try selecting AccountId for a M-D relationship and choose the child records(with 'for update' in the loop) for lookup relationships and try and see...
    – SF Learner
    Commented Jun 7, 2016 at 0:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .