0

I am updating the parent record of a record upon edit/save. However, if I update multiple records in that child object at the same time I get an error for excessive amount of updates to the same record.

I'm doing all of this by using a Process to kick off a Flow.

So, the Process is getting invoked multiple times when multiple records are edited upon the same save. I don't know how to not edit the parent multiple times in the same batch call.

Any help would be appreciated.

2
  • In your PB or flow, could you schedule the actions with 5s intervals or something to that nature so the call isn't executing everything at once? – Geo Feb 20 '19 at 19:13
  • I was thinking of this as well, but I don't believe I can use a denomination as low as 5s in a scheduled action within a Process or Flow. I think the lowest I can go is 1hr. Or at least that's all I've seen. – Zoom_v Feb 20 '19 at 19:30
2

Unless you can somehow change the conditions for the update so that not all children match at once, you're going to need some Apex Code to handle this problem. It could be an Invocable Method or an Apex trigger.

4
  • Thank you @sfdcfox - I'm trying to wrap my head around that. Would that class just be initiated through a trigger ? And I still don't see how that would prevent multple runnings of that same class since there will still be multiple records saved. – Zoom_v Feb 20 '19 at 19:42
  • 1
    @Zoom_v You need either an Invocable Method (to be called from the PB), or an Apex trigger. The point here is that you need to "bulkify" the logic. The first does this because of how PB works (all triggered records will enter the method at once), the trigger method works because you get to see all the children and can modify the parent using a Map object. Either way is up to you, they both require code. – sfdcfox Feb 20 '19 at 19:45
  • I still don't understand how I would prevent the PB from invoking the class 3 times if 3 records are being sent into the Process at the same time. Won't the invokablemethod just be run 3 times and produce the same results as now, updating the same parent record three times ? I'm sorry if these are stupid questions. – Zoom_v Feb 25 '19 at 18:24
  • 1
    @Zoom_v Invocable Methods accept a list of values (records) to work against, and do so in a bulkified manner. In your method, you would create a map (Map<Id, Parent> parents), and apply the updates to distinct parents at once. It is the same identical concept as bulkifying updates in a trigger against parent records. – sfdcfox Feb 25 '19 at 19:11

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.