0

Here is the scenario:

I have a record triggered flow on Opportunity Product (OpportunityLineItem) object insert & update. When OPL(OpportunityLineitem) is inserted or updated of a particular product family, then a custom field is updated with the Quantity of that OPL. Also whenever OPL is inserted from that family the quantity of this OPL will get added to the Opportunity custom field. So basically the Opportunity field will be the sum of the quantity of the products (of same product family) added through OPL.

scenario -> Opp1 - Opp_field__c
OPL1 -> Family1 - Quantity - 20
OPL2 -> Family1 - Quantity - 30

expected result -> Opp_field__c - 50
actual result -> Opp_field__c - 30

flow criteria ->record triggered on insertion/update -> assignment -> Opp_field__c is added with the quantity of OPL inserted/update.

Things to note: This is happening only when I am trying to add both the OPL at once and trying to update the field from same opportunity but for different OPL records that triggered the flow

1 Answer 1

2

So, this happens because each OpportunityLineItem DML has its own Flow Interview which executes using the same starting condition for all records.

Since the second Interview is unaware of the update made by the first interview, the second interview simply adds 30 to the value of the Opportunity when the transaction started (i.e. 0). Remember - Flow bulkifies its GET, UPDATE, CREATE, and DELETE actions across all the Flow Interview.

  • Flow Interview 1 (prepares a DML Update of Opp_Field__c = 0+20)
  • Flow Interview 2 (prepares a DML update of Opp_Field__c = 0+30)

When the transaction ends (both OLI records), SFDC bulkifies the update into a single DML operation - and takes the last interview's update as the winner.

Alternatives

  • Use DLRS to rollup all qualifying OLIs into the parent Opportunity. DLRS, like Roll-Up Summaries can do SUM operations
  • Use shadow fields on the OpportunityLineItem to capture the related Product2.Family field (using triggers, beforesave flows) and then use RSF criteria to rollup to the parent
  • Have the Flow escape to an Apex invocable action (which is bulkified) that can do the sum operation in DML to the parent Opportunity
  • Use one of the UnofficialSF.com rollup components. UnofficialSF.com is a super helpful resource for Flow developers
1
  • Thanks for responding
    – SFDC IN
    Commented Feb 5, 2022 at 4:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .