I'm working on a scheduled flow which will delete all the Group Members present in a group after which I can add the required Group Members. But when the flow runs in scheduled mode it throws an error 'UNABLE_TO_LOCK_ROW' on delete element. Also, there's an interesting thing when I run this flow in debug mode, I don't get any errors and all the operations are performed perfectly. I would like to know why I don't get any errors while running it in Debug mode either in rollback mode or not.
I guess the reason for this error could be that the Parent object (i.e: Group) is getting locked while other child objects (i.e: GroupMembers) are being deleted at the same time. And, if I could run this in smaller batches I won't be getting this error, but this option is not feasible in Scheduled Flow.
I would really appreciate any help on this, feel free to get any other input from me. Thanks!
I tried to replicate the flow (3 nodes - Get Group, Get Member and Delete Member) and it worked fine (the group members were removed).
So next thing to try (as it seems more specific to your org / data) :-
1. In the original screenshot, it cause a lock on a particular group member. Can you please check if that group member is a user (and not a role / queue / group / etc.)?
2. For the Get All Group Members Weekly, instead of all records, choose 1 record and run it to see the error. (you might have to run multiple times to get the error). In case it fails on 1st run, just change sort order. If it still fails, try to manually remove that group member.
3. Try removing all group members manually and then just 1 add user to see if locking persists.
4. Now talking about the strategy, it might not be good to remove all and add all - This can result in a lot of sharing recalculation. It is better to only remove / add the ones that need to be done.
In 1,2 & 3 we are trying to debug to find if it is data issue or there is something else that is going wrong.
however I would still recommend to consider point 4.