Attempt to Authenticate then execute authenticated API request with minimal code in a componentized/modularized fashion.
Standardized Flow which takes parameters from an sObject and passes to an invocable method and ultimately an API_Handler class.
Future Class which parses and constructs an API call, then executes the API call, parses the response and starts a flow interview, Helper_Outbound_API_Response.
Takes parameters and generates a log (in a custom object). Has logic to generate a case if API Response is unsatisfactory.
I have a process builder which fires on creation of a record. The process builder ultimately calls the Helper_Outbound_API_Request flow mentioned above - chaining the execution of the following two processes mentioned above (API_Handler and Helper_Outbound_API_Response). Up to this point, everything is working great - record insertion executes API Call and logs response. This initial API Call was for authentication.
I then have another process builder which executes on a Log insert (i.e. where the API Response is stored). This process builder follows a similar process in that it takes that response, parses the information, and passes it to the Helper_Outbound_API_Request to execute another request - the update itself.
Given the secondary process builder was executed off of a @Future method, the second API call is throwing the error:
An Apex error occurred: System.AsyncException: Future method cannot be called from a future or batch method. My expectation was that on save of the Log record the transaction ends and would exit the @Future context - can anyone verify that's incorrect?
I'd like to leave the code generalized so we won't have to write an API Method again... only invoke it via the Helper_Outbound_API_Request I built and handle variances via parameters. Is there any way around my above issue?
The only design work around I can think of here is build in authentication handling to the method, which breaks my requirement of having a single generalized API Method - the authentication payload is going to vary by API call made and therefore require logic to handle any API Call we want to make.
Given I am going to have DML transactions after my authentication request, but before my update request, will that prevent my update request from executing because of transactions in progress? For example, I'm trying to avoid this issue.