function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
cjencjen 

How to launch a flow from a trigger after delete?

hi, i have a flow that counts all of the assets related to account and updates a number field on the account. This works for new assets but i am not able to launch the flow if an asset is deleted. I am understanding that a trigger can be created to do this, maybe after delete? I need to pass the AccountId of the deleted asset into the flow. i researched and found a sample flow code.

the scenario would be a user deletes an asset record which triggers the flow to count all the assets related to the same account the deleted asset was related to, and then update a number field on the account with the new value. Any help is greatly appreciated, thanks!
 
Flow.Interview flow = new Flow.Interview.MyFlowApiName(new map<String,Object> 
                                                {'vAccountId' => aId});     
flow.start();
ANUTEJANUTEJ (Salesforce Developers) 
Hi Cjen,

I searched for the same i.e., for a way to call a flow from a trigger so that after performing your operations in trigger you can invoke the flow, but unfortunately I also found the same way that you have specified, can you please mention if the above way is working or not?

Regards,
Anutej
cjencjen
Hi Anutej, not i have not. i need help building the entire trigger to include that code. would you be able to help? thanks!
ANUTEJANUTEJ (Salesforce Developers) 
Hi Cjen,

I believe you can use the following steps to get to your desired functionality.

>> create a trigger to performe for before delete operation.

>> get the ids for the records which have been changed.

>> the above you can do by getting id's from trigger.new.

>> get all the id's from account where the asset id's are in the above list.

>> Perform your operations of changing values and updating the values to the DB.

>> After this as a last step you can call the flow so that you can perform the operations in flow.

Regards,
Anutej