I am having a difficult time architecting the flow of declarative work to, and from, apex code.
What I want the flow to be is:
- Apex Trigger
- Flow (sends inputs to webservice)
- Webservice Callout (Process.Plugin or InvocableMethod)
- Flow (takes outputs from webservice)
My issues:
- Because you can not call a webservice from a Trigger, I must make the callout a future method. Because the callout is a future method, you cannot use static variables to return the value from the future method to the synchronous code that called it. Aka I can not pass back output parameters into the flow.
- Work Around 1: Create a process builder rather then the trigger to avoid future methods. Because of the order of DML and Callouts, I will always get an "Uncommitted Work Pending" error. The flow will make the DML and Callout loop thus causing DML to happen before and after the callout.
- Work Around 2: perform a DML update on the record after making the callout and do not pass back any parameters to the flow. Because of the async/sync differences between the callout, there is a delay between when the future method makes the insert and when the next block of the flow is fired. I need the Object to be inserted before it can move on to the next block in the flow. Due to the nature of the flow, it loops through multiple times thus causing the same error
You have uncommitted work pending. Please commit or rollback before calling out
Does anyone have any suggestions (other then platform events) to allow the data to be passed to and from a flow and webservice? I feel like there must be a way to make option #1 work.