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
Tobias LetznerTobias Letzner 

Callout failed trying to call a flow with an external service IM from a process

Im trying to call a flow from a process to start an invocable method.
The process waits for a certain status on the case object to start the flow with a scheduled action: 

User-added imageI get a 'pending uncommitted changes' error everytime I try do call the flow. 

My flow looks like this: 
User-added image

Any suggestions?
VinayVinay (Salesforce Developers) 
Hi,

The issue occurs when you first perform DML and then callout in the same transaction. You need to perform Callout in the future method so your callout and DML will be in the different transaction.

Call future methods from process builder, call the future method from the in-vocable method. 

Sample Code:
===========
public class LightningProcessBuilder {
    @InvocableMethod 
    public static void sendEmailToOwner(List<String> listUserNames) {
        callEmailSend(listUserNames);
    }
    @future
    public static void callEmailSend(List<String> listUserNames) {
        //Write the logic.
       //If it is a call out, use callout = true in future annoation
    }
}

Review below links for more information.

https://help.salesforce.com/articleView?id=000328873&type=1&mode=1
https://help.salesforce.com/articleView?id=000326129&type=1&mode=1
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_callouts_wsdl2apex_testing_dml.htm
https://salesforce.stackexchange.com/questions/120012/problem-with-process-builder-invocable-method-and-webservice-call-out

Hope above information was helpful.

Please mark as Best Answer so that it can help others in the future.

Thanks,
Vinay Kumar
Abhinav jain 20Abhinav jain 20
But when it is an external service we can't access the class directly and can't write the @future their, in that case what should we do?
Jill Hulsker 3Jill Hulsker 3
Tobias, did you ever figure this out? I am running into the same problem.
John Storey 17John Storey 17

+1

Need to run an External Service while creating and updating records that are relevant to the ES.