2

Suppose I have this structure:

The class with @InvocableMethod:

global with sharing class GetAllOrgsAction {
    global class responseObjectAPI {
        @InvocableVariable global List<DTO.Organization> data;
        @InvocableVariable global DTO.Meta meta;
    }

    global class requestObject {
        @InvocableVariable global String access_token;
        @InvocableVariable global Integer page;
        @InvocableVariable global Integer per_page;

        global requestObject() {}

        global requestObject(String access_token, Integer page, Integer per_page) {
            this.access_token = access_token;
            this.page = page;
            this.per_page = per_page;
        }
    }

    @InvocableMethod(Label='Get a list of organizations')
    global static List<responseObjectAPI> run(List<requestObject> requests) {
        Http http = new Http();
        List<responseObjectAPI> responses = new List<responseObjectAPI>();

        for (requestObject request_i : requests) {
            HttpRequest req = /*...*/;
            HttpResponse res = http.send(req);
            responses.add((responseObjectAPI) JSON.deserializeStrict(res.getBody(), responseObjectAPI.class));
        }

        return responses;
    }
}

The DTO class:

global with sharing class DTO {
    global class Auth {
        @InvocableVariable global String id_token;
        @InvocableVariable global String token_type;
        @InvocableVariable global Integer expires_in;
        @InvocableVariable global String access_token;
        @InvocableVariable global String refresh_token;
    }

    global class Meta {
        @InvocableVariable global Integer total;
        @InvocableVariable global Integer current_page;
        @InvocableVariable global Integer per_page;
        @InvocableVariable global Integer last_page;
    }

    global class Organization {
        @InvocableVariable global String id;
        @InvocableVariable global String name;
        @InvocableVariable global String subdomain;
        @InvocableVariable global String category;
        @InvocableVariable global String size;
        @InvocableVariable global String status;
        @InvocableVariable global String created_at;
        @InvocableVariable global String updated_at;
    }
}

I am calling Apex Action from salesforce flow. For the output I have data array and meta object, but I cannot get any property of meta object, for example, last_page.

Am I missing something? The documentation says:

The data type of the invocable variable must be one of these:

A list or a list of lists of primitives, sObjects, objects created from Apex classes, or collections

Just for your information. In this case (code example below) I can access properties of DTO.Auth:

global with sharing class AuthAction {
    global class requestObject {
        @InvocableVariable global String username;
        @InvocableVariable global String password;

        global requestObject() {}

        global requestObject(String username, String password) {
            this.username = username;
            this.password = password;
        }
    }

    @InvocableMethod(Label='Get access token (Password grant)')
    global static List<DTO.Auth> run(List<requestObject> requests) {
        Http http = new Http();
        List<DTO.Auth> responses = new List<DTO.Auth>();

        for (requestObject request_i : requests) {
            HttpRequest req = /*...*/;
            HttpResponse res = http.send(req);
            responses.add((DTO.Auth) JSON.deserializeStrict(res.getBody(), DTO.Auth.class));
        }

        return responses;
    }
}

Clarification with screenshots:

Flow definitely see the class: enter image description here But the object is empty: enter image description here If I try to manually print subdomain there, I get: enter image description here

8
  • 1
    I wonder if there is a name clash between your DTO Organization class and the Organization SObject that is causing the problem?
    – Phil W
    Commented Jul 17 at 13:26
  • @PhilW Nope, for registered name it does not allow you to save Apex class, for example, if I try to name the class in DTO as Field. However, the Meta class is definitely does not have any collisions with sObjects, but still - cannot access its properties. Commented Jul 17 at 13:29
  • Tried to rename it, but to no avail. Commented Jul 17 at 13:32
  • 1
    I misread my earlier answer -- @AuarEnabled on each @InvocableVariable in the outer class Meta, etc
    – cropredy
    Commented Jul 17 at 16:30
  • 1
    @cropredy Thanks, that worked! Commented Jul 17 at 18:45

1 Answer 1

2

@cropredy was right:

  • You need to make inner classes as outer classes on their own.
  • You need to add @AuraEnabled in the outer class.

So here is the final result:

The responseObjectAPI class from the class with @InvocableMethod:

global class responseObjectAPI {
    @InvocableVariable global List<DAH_Organization> data;
    @InvocableVariable global DAH_Meta meta;
}

The DAH_Organization outer class moved away from DTO class:

global class DAH_Organization {
    @AuraEnabled @InvocableVariable global String id;
    @AuraEnabled @InvocableVariable global String name;
    @AuraEnabled @InvocableVariable global String subdomain;
    @AuraEnabled @InvocableVariable global String category;
    @AuraEnabled @InvocableVariable global String size;
    @AuraEnabled @InvocableVariable global String status;
    @AuraEnabled @InvocableVariable global String created_at;
    @AuraEnabled @InvocableVariable global String updated_at;
}

You must log in to answer this question.

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