Skip to main content

Hi Trailblazer Community,    I am working on a Salesforce Flow solution for Account merges and would appreciate guidance.    When two duplicate Accounts are merged, the surviving Account should automatically recalculate two custom count fields updated by a flow    Current design:  I built this as a two-part flow process.    Flow 1:  Record-Triggered Flow on Account  Trigger: A record is deleted  Optimize for: Before the record is deleted  Entry condition:  MasterRecordId Is Null False    Purpose:  When an Account is deleted because of a merge, the flow creates a Platform Event record.    Flow 2:  Platform Event-Triggered Flow     Purpose:  When the Platform Event is received, it uses Surviving_Account_Id__c to:    1. Get all related Case Records   2. Count those records.  3. Get active x Records where:  4. Count active records.  5. Get the surviving Account.  6. Update Account if necessary         What I confirmed:  The Platform Event is deployed and has Publish Behavior = Publish After Commit.    The Platform Event-triggered flow is subscribed and running.    When I manually publish the Platform Event through Developer Console, Flow 2 works correctly and updates the Account counts.    After this manual publish, the Account count fields update correctly.    Issue:  When I perform an actual Account merge, the surviving Account counts do not always update automatically.    I confirmed that the losing Account has:  IsDeleted = true  MasterRecordId = surviving Account Id    So Salesforce is populating MasterRecordId correctly.    Question:  Is there anything about Account merge delete behavior, before-delete flows, or Platform Event publishing from a record-triggered delete flow that would prevent the Platform Event from being published or processed as expected?    Also, is there a better declarative pattern to recalculate rollup-style count fields on a surviving Account after an Account merge? DLRS    Any guidance would be appreciated.    

6 answers
  1. Jul 17, 1:38 AM
    @Liam Vukasinovic

    - A before-delete Flow could run too early, before SF finishes moving the losing Account’s related records to the winner. That seems produce an outdated count.

    What worked reliably was a small after-delete Apex trigger that sends the winning Account Id to a Platform Event Flow. The Flow then recounts the related records after the merge finishes and updates the Account only when needed.

0/9000