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
Stefaan Somers 11Stefaan Somers 11 

Help Needed: Resolving APEX CPU Timeout in Lightning Flow with HTTP Callout - Unable to call ExternalService from callout in APEX class

Hi Salesforce Community,
I'm working on a lightning flow that's scheduled to run and perform specific tasks. The flow's main objective is to retrieve records with a certain status and loop through these records to make an HTTP callout.

Here's a brief overview of the process:
  • The flow assigns values to a custom instance 'body' of the type ExternalService apex class ExternalService__SendReminder_SendReminders_IN_body which is generated by Salesforce.
  • The primary task is to make an HTTP callout using these values.
Issue Encountered:
I'm consistently hitting an APEX CPU timeout limit. To address this, I've considered creating a platform event where I can publish an event with the JSON value of the 'body' variable. However, this isn't directly feasible in the flow, leading me to consider developing an invocable Apex class.

Here's the draft of the class I'm contemplating:
 
public class JsonUtility {

    public class RequestWrapper {
        @InvocableVariable
        public ExternalService.xxxx  myVariable;
    }

    @InvocableMethod
    public static List<String> serializeToJson(List<RequestWrapper> requests) {
        List<String> jsonStrings = new List<String>();

        for (RequestWrapper req : requests) {
            jsonStrings.add(JSON.serialize(req.myVariable));
        }

        return jsonStrings;
    }
}

Challenge:
I'm unable to locate the class ExternalService__SendReminder_SendReminders_IN_body in the IDE, which Salesforce generates. However, it is visible in the Dynamic class of Apex classes overview in Setup.

I'd greatly appreciate any insights or advice on the following:
  • How to effectively resolve the APEX CPU timeout issue in this scenario?
  • Why the generated class is not visible in the IDE and how to access it for development purposes?
Any help or pointers in the right direction would be immensely valuable.
Thanks in advance for your assistance!