1

Ideally, we will create an External Service based on the API Schema and use it in Flows. For some reason, when we do callouts in the Flow, the API cannot parse the Authorization header correctly, returning us a 403. However, when we do the same callout in Apex using setHeader, the API can correctly read the Authorization header.

Our requirement is that we have to use Flows, but since we are having issues I am experimenting with a workaround, which is as follows:

  1. Create External Credential / Named Credential
  2. Create External Service
  3. Create a Flow
  4. In the flow, create an Apex-Defined Data Type of a External Service Dynamic Apex Datatype
  5. Create Apex class which has Invocable Method to be accessed from Flow
  6. Call the API using Apex (HttpRequest)
  7. Deserialize the response body JSON into the already created External Service Schema
  8. Return the deserialized JSON back to the Flow
  9. Returned data is stored in the variable of Apex-Defined Data Type from step 4

enter image description here

The Apex code is somewhat along the lines of:

public with sharing class GTW_getAllAccountWebinars 
{
    @InvocableMethod(label='Get All Webinars')
    public static List<ExternalService.GTWExternalService2_ReportingWebinarsResponse> getAllWebinars(List<String> bearerToken)
    {   
        HttpRequest request = new HttpRequest();
        request.setEndpoint('callout: GTW_Named_Credential');
        request.setMethod('GET');
        request.setHeader('Authorization', 'Bearer ' + bearerToken);
        HttpResponse response = new Http().send(request);   

        ExternalService.GTWExternalService2_ReportingWebinarsResponse APIresponse = (ExternalService.GTWExternalService2_ReportingWebinarsResponse)System.JSON.deserialize(response.getBody(), ExternalService.GTWExternalService2_ReportingWebinarsResponse.class);
        List<ExternalService.GTWExternalService2_ReportingWebinarsResponse> responseBody = new List<ExternalService.GTWExternalService2_ReportingWebinarsResponse>();
        responseBody.add(APIresponse);    
        return(responseBody);
    }
}

So the data returned from GTW_getAllAccountWebinars class is being sent back to the Flow for further processing.

However, the issue I am facing is that the Apex class is returning the following error:

InvocableMethod methods do not support return type of List<ExternalService.GTWExternalService2_ReportingWebinarsResponse>

I am aware that we have to implement wrapper classes to return custom data types, but I don't want to write the entire schema manually using wrapper classes, when I have the schema already created dynamically using External Services.

Hence, my question is how can I return External Service data type from an Invocable Method?

1 Answer 1

1

You can't return it because the Apex Object doesn't have the necessary @AuraEnabled annotation and it's an inner class.

Only outer classes with variables annotated with @AuraEnabled can be used.

You will need to create a Class to hold the relevant variables and return that instead, you can put them in your GTW_getAllAccountWebinars class, or you can create a totally separate class if you want to.

Checkout this it should give you a bit more info.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .