I call an invokable apex class method, that in turn calls an external REST service. How do I send the http response back to the flow? Am I missing the invokable return variable?

    public class obuTopUpTrailhead {
// Call this method from flow
    public static void invokeapexcallout(list<String> obuDetails){
    for (string s : obuDetails){

// http callout method
public static HttpResponse PutCallout(String pName) {
    System.debug('Incoming String is :' + pname);
    String FullString   = pname;
    String[] OBUdetails = fullstring.split(',');
    String recordid     = OBUdetails [0]; 
    String obusn        = OBUdetails [1];
    String topup        = OBUdetails [2];
    String cardnumber   = OBUdetails [3];
    // Make JSON conversion
    JSONGenerator gen = JSON.createGenerator(true);    
    gen.writeStringField('OBU Record ID ', recordid);
    gen.writeStringField('OBU S/N', obusn);
    gen.writeStringField('Top up Amount', topup);
    gen.writeStringField('Card Number', cardnumber);
    String jsonS = gen.getAsString();
    // Sending the http body with JSON
    String endpoint = 'http://www.example.com/service';
    HttpRequest req = new HttpRequest();
    Http http = new Http();
    HTTPResponse response = http.send(req);
    // Parse the JSON response
    if (response.getStatusCode() != 201) {
        System.debug('The status code returned was not expected: ' +
            response.getStatusCode() + ' ' + response.getStatus());
    } else {
    return response;



Funny... I just got done figuring this out myself:

You have to first create a class for all the values in your json response body. Then, deserialize the response.getbody() referencing the newly created class.

Does that make sense?

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.