I have a FLOW that works successfully when Opportunity Product (OpportunityLineItem) records are created or update but not when one is removed. This is because a FLOW even when set to "When a Record is Deleted" runs as "before delete" and I need it to fire as "after delete".
It's a Auto Launched flow that is called as a Sub Flow when Opportunity Product is created or updated. A single text variable is passed through to it called opportunityID representing the 18 digit ID of the OpportunityLineItem.OpportunityId
The flow then does a Get Record to gather in all the child Opportunity Produccts and performs a series of calculations before writing the answer back onto the Opportunity record. It does this very successfully.
My attempt to write an after delete trigger is below.
trigger OpportunityProductAfterDelete on OpportunityLineItem (after delete) {
MAP<String,Object> inputs = new Map<String,Object>();
for (OpportunityLineItem OPLI : trigger.old){
inputs.put(OPLI.opportunityId,OPLI);
}
Flow.Interview.apiFlowName myFlow = new Flow.Interview.apiFlowName(inputs);
myFlow.Start();
}
I can see from the LOG files that the Flow is indeed running but it doesn't do anything. I suspect the problem is with my inputs.
Possibly the FLOW which takes a text variable representing OpportunityID should instead be taking a record variable representing Opportunity.
Possibly my APEX code is just wrong.
Appreciate any assistance.