You need to sign in to do that
Don't have an account?

Call and Pass Variables to Flow via Apex Class/Trigger
Hi,
I've created a flow that updates an opportunity text field with the names of the products associated with that opportunity (separated by semicolons). This field should be updated whenever a new product is added or deleted, so I need to be able to invoke this flow with a trigger rather than just process builder. I've looked at a lot of different resources, but I can't seem to find something that explains how the apex class and trigger work together to call the flow and pass variables from the trigger/class to the flow. Would seriously appreciate any guidance or code snippet anyone could offer!
Thanks!
I've created a flow that updates an opportunity text field with the names of the products associated with that opportunity (separated by semicolons). This field should be updated whenever a new product is added or deleted, so I need to be able to invoke this flow with a trigger rather than just process builder. I've looked at a lot of different resources, but I can't seem to find something that explains how the apex class and trigger work together to call the flow and pass variables from the trigger/class to the flow. Would seriously appreciate any guidance or code snippet anyone could offer!
Thanks!
Check below link which has sample code that can help you.
https://andyinthecloud.com/2014/10/26/calling-flow-from-apex/
Best Regards,
Sandhya
You can retrieve flow variables for a specific flow in Apex.
The Flow.Interview Apex class provides the getVariableValue method for retrieving a flow variable, which can be in the flow embedded in the Visualforce page, or in a separate flow that is called by a subflow element. This example shows how to use this method to obtain breadcrumb (navigation) information from the flow embedded in the Visualforce page. If that flow contains subflow elements, and each of the referenced flows also contains a vaBreadCrumb variable, the Visualforce page can provide users with breadcrumbs regardless of which flow the interview is running.
Refer this links
https://andyinthecloud.com/2014/10/26/calling-flow-from-apex/
https://salesforce.stackexchange.com/questions/205654/flow-calling-apex-cant-pass-collection-variable
https://salesforcesidekick.com/2015/06/29/how-to-passing-a-new-variable-out-of-flow/
http://leehildebrand.name/?p=223
https://andyinthecloud.com/2014/10/26/calling-flow-from-apex/
https://stackoverflow.com/questions/10032799/how-do-i-get-a-variable-back-from-a-flow
Thank you both for the input! Does the below class make sense? I'm getting the following compile error when I try to save it:
Error: Compile Error: Expecting ')' but was: 'varOpportunityId' at line 11 column 19
Also, below is the trigger. I'd like for this to fire whenever an OpportunityLineItem is created or deleted. Are my events correct?