+ Start a Discussion
Stephanie KellishStephanie Kellish 

Scheduled Flows: prevent locked parent records/parallel batches

In our scheduled daily flow, which runs every morning, we fairly regularly get an error that the parent object ("Parent") of the object the flow is running on and updating ("Child") causes an UNABLE_TO_LOCK_ROW error, specifically referencing that Parent records are being locked multiple times and throwing an error. This seems to be because Child records that have the same parent are running/updating in parallel, in different batches, which causes the lock on the parent to be tripped twice (causing the error). There are no conflicting Apex jobs or other scheduled flows scheduled anywhere near this time period, and it is scheduled at a time where we do not have employees working.

I would like to know if there is any way to either
1) run the batches in a scheduled Flow serially, instead of in parallel, or
2) ensure that all child records with the same parent record are included in the same batch, so that the lock does not get placed twice and cause an error.
ShirishaShirisha (Salesforce Developers) 
Hi Stephanie,


I don't think we can run the batches in the scheduled flow serially as we can't change it from our end as it is flow.

But,you can actually process all the child records first based on the parent record to avoid the Row lock errors.

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
Stephanie KellishStephanie Kellish
Thanks Shirisha! That's good to hear that we're able to process the child records based on parent record, but I haven't been able to find the option! I know you can do things like sort collection variables gathered through a "Get Records" by the parent record value, but I haven't found a way to do so on a Scheduled Flow running on the "$Record". Do you know how this would be accomplished?
Alex Skempris 18Alex Skempris 18
Hi Stephanie, have you found a solution to this? I'm facing a similar issue. And there doesn't seem to be a way to reduce the batch size either.
Stephanie KellishStephanie Kellish
Unfortunately not Alex - and in a different thread I posted to try to get answers on how to process child records based on parent records, I was told that processing child records ordered by parent actually wasn't possible. Looks like until Flow is updated with the capability, Apex is the only way to choose batching preferences.
Henrik HeltHenrik Helt
Hi Stepanie,
I had the similar issue. I have a sceduled job running on a daily basis which set either Active or Inactive based on some Salesforce System fields (Service Contract Line Items). In my Original Flow Conditions I accepted two different conditions eigther set as Active or set as Inactive. The entry criteria was followed by a decision element telling the flow to set the record either as Active or Inactive.
I solved the Record Lock problem when I decided to Clone my flow and in the entry criteria only accepting one scenario and of course scedulded these flow to run on different time slots.
  1. Flow 1 - only look for Contract Line Items which should be marked as Active
  2. Flow 2 - only look for Contract Line Items which should be marked as InactiveOriginal Entry Filter ConditionsNo Record Lock 
du doan xsmbdu doan xsmb
Dự đoán soi cầu xổ số miền Bắc là chuyên mục được nhiều người theo dõi vì tính tiện dụng của chúng đối với người thường xuyên tham gia xổ số miền Bắc. Xem ngay: https://xsmb99.me/du-doan-xsmb.html