I have a one to many relationship between Project and Insurance. When a record is created on Insurance object, it needs to get the Project record and then count how many Insurance records are present and it needs to input the value in the Name field of the Insurance record.

I used a flow to implement the same and it works when I create records one by one but works wrongly when I try to mass upload it.


enter image description here

Here the first two records are manually created which works fine whereas the next two records are mass uploaded and it takes the same reference numbers as 004.

enter image description here

  • Flows process records in batches of 200. Could it be the case? Try uploading more than 200 records and see if batches of 200 records have the same counter.
    – Naga
    Feb 15 '21 at 4:16

Naga's comment is (at least partially) correct.

What happens is that each Flow is evaluated in turn, in a round-robin sort of way, pausing each Flow when it reaches a DML or Query block. Once all Flows are paused because of this condition, all of the query conditions or DML operations are grouped into a single action for bulkification, and then the query or DML operation is executed.

If you look at the logs, you'd see something like:

Start Flow #1
Start Flow #2
Get Project #1 (wait)
Get Project #2 (wait)
Project Query
Get Insurance #1 (wait)
Get Insurance #2 (wait)
Insurances Query
Assign Count #1
Update Record #1 (wait)
Assign Count #2
Update Record #2 (wait)
Insurances DML
End #1
End #2

So, in your code, each Flow reaches the Count Insurance Records step, then both of the new records are found, and so the Assignment afterwards sees the count at 4, which is what gets assigned to each record.

There's no way to resolve this using only Flows. This is one of several different limitations with Flows in regard to bulkification; they cannot communicate with each other to coordinate counting records correctly. You would need a trigger in order to fix this problem.

To avoid the problem for uploading, assign your records so that no two Insurance records for the same Project are within the same 200 records.

You can read more about this in Flow Bulkification in Transctions.

  • Thanks @sfdcfox. You are the best! Do you think is there any other way I could achieve the same using declarative means? I understand your point fully. Feb 15 '21 at 11:27
  • 1
    @Krishnamurthy Not without some code involved, as far as I can think of.
    – sfdcfox
    Feb 15 '21 at 14:42

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.