0

We have 2 objects - ObjectA and ObjectB. Object B has a lookup to ObjectA (so ObjectA is parent and ObjectB is child). We need to calculate no. of Active ObjectB records and show it in ObjectA record page. If it was M-D relationship, roll-up summary field was the solution, unfortunately it is not and it cannot be. We cannot have a report chart shown since this field is used for various other calculations.

So, we used Process Builder + Flow to calculate the no. of Active ObjectB records. On create/update of ObjectB, we pass the ObjectA__c reference to the flow, get all the ObjectB filtered on Status = Active and store it in a list variable. This happens in the loop element of flow and outside the loop element (after last), we update ObjectA's ActiveCount__c field.

References - https://success.salesforce.com/answers?id=90630000000476cAAA https://admin.salesforce.com/use-flow-builder-to-create-a-roll-up-summary-field Create a roll-up summary field on Lookup without coding

This was all good when we tested by creating ObjectB records. But now when do proper testing, where we had 20 ObjectB records inserted, we got DUPLICATE_VALUE: Maximum number of duplicate updates in one batch (12 allowed). Attempt to update Id more than once in this Api call: ObjectAId

I am wondering if this is known issue. But as per documentations, Salesforce suggests that Flows are bulkified. Is this truly bulkified or am I doing something wrong?

2

Process Builder and Flows are bulkified (e.g. you can safely update a field on 200 records at once), but they can't handle the situation where a single record is updated a large number of times in the same transaction (more than 12). Unfortunately, Flows and Process Builder aren't great at updating parent records in a bulk pattern, and there's no way to make something that resembles a "map" in the Flow engine. You will need to use Apex, either by way of an InvocableMethod or just writing a trigger to enable mass updates in a safe manner.

  • So the "solution" of creating rollup summary using PB + Flow is not feasible? – goabhigo Jul 19 at 5:20
  • @goabhigo Correct. Even if you got past this problem, you'd run in to others (e.g. Flows can't trigger on deletion of a record). Apex remains the only viable way to do this. Have you looked at DLRS? – sfdcfox Jul 19 at 5:25
  • Yes, now looking into those as I read it somewhere (now not finding it, I will paste it again when I find it) that Flows are bulkified. I guess by bulkified they mean upto 12 records. Thank you Brian. – goabhigo Jul 19 at 5:32
  • @goabhigo No, the Flow engine aggregates updates by advancing all elements in multiple updates at once, instead of executing one flow at a time. The 12 record limit is actually just related to the API limit for duplicate records per transaction. – sfdcfox Jul 19 at 5:33
  • 1
    @goabhigo The docs you're looking for are here. – sfdcfox Jul 19 at 5:36

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.