0

Continuig from the issue I posted just a few hours ago - Returning a list of lists to the flow returns error saying list out of bounds

Here is my Apex action with the Invocable Method-

public with sharing class AuthPINPasswordController {

    @InvocableMethod(
        Label='getPINPassword'
    )
    public static List<List<CustomerAccountContactDto>> getPINPassword(List<Request> requestList) {

        List<List<CustomerAccountContactDto>> customerAccountcontacts = new List<List<CustomerAccountContactDto>>();
        List<CustomerAccountContactDto> contacts = new List<CustomerAccountContactDto>();

        CustomerAccountContactDto response = new CustomerAccountContactDto();
        CustomerAccountContactDto response1 = new CustomerAccountContactDto();

            
        response.errorOcurred = false;
        response.customerAccountContacts[0].contactName = 'Contact1';
        response.customerAccountContacts[0].contactRoleType = 'Primary';
        response.customerAccountContacts[0].decryptedPassword = 'decryptedPassword';
        response.customerAccountContacts[0].passwordChangeIsRequired = false;
        response.customerAccountContacts[0].passwordIsSet = true;
        response.customerAccountContacts[0].hintText = 'hintText';
        contacts.add(response);

            
        response1.customerAccountContacts[1].contactName = 'Contact2';
        response1.customerAccountContacts[1].contactRoleType = 'Secondary';
        response1.customerAccountContacts[1].decryptedPassword = 'decryptedPassword1';
        response1.customerAccountContacts[1].passwordChangeIsRequired = false;
        response1.customerAccountContacts[1].passwordIsSet = true;
        response1.customerAccountContacts[1].hintText = 'hintText';
        contacts.add(response1);

        customerAccountcontacts.add(contacts);
        return customerAccountcontacts;
    }

    public class Request {
        @InvocableVariable(required=true)
        public String accountNumber;

        @InvocableVariable(required=true)
        public String objectId;

        public Request(String accountNumber, String objectId) {
            this.accountNumber = accountNumber;
            this.objectId = objectId;
        }

        public Request() {} //NOPMD
    }

    public class Result {

        @AuraEnabled @InvocableVariable(required=true)
        public String contactName;

        @AuraEnabled @InvocableVariable(required=true)
        public String contactRoleType;

        @InvocableVariable(required=false)
        public String decryptedPassword;

        @InvocableVariable(required=false)
        public String hintText;

        @InvocableVariable(required=false)
        public Boolean passwordChangeIsRequired;

        @InvocableVariable(required=false)
        public Boolean passwordIsSet;

        public Result() {
            //set defaults
            this.passwordChangeIsRequired = false;
            this.passwordIsSet = false;
        }
    }
}

And here is Apex Defined Class which is in its own file and which I am referring and returning to the flow on the above invocable method -

public with sharing class CustomerAccountContactDto {
    public CustomerAccountContactDto() {
        this.errorOcurred = false;
        this.errorMessage = '';
    }

    @AuraEnabled @InvocableVariable(required=true)
    public Boolean errorOcurred;

    @AuraEnabled @InvocableVariable(required=true)
    public String errorMessage;

    @AuraEnabled @InvocableVariable(required = true)
    public List<AuthPINPasswordController.Result> customerAccountContacts;
}

Here is my Apex Defined collection variable created inside of the flow- enter image description here

And here is how I am setting it as output to the apex action -

enter image description here

When trying to print the value of one of the fields of the collection variable, I don't see an arrow that shows all the @AuraEnabled variables on the left to select the variable.

Now how do I access the individual fields of the collection variable on a screen component. The collection variable should be pointing to three fields as shown below and I need to send the 3rd variable to a LWC component as well.

@AuraEnabled @InvocableVariable(required=true)
public Boolean errorOcurred;

@AuraEnabled @InvocableVariable(required=true)
public String errorMessage;

@AuraEnabled @InvocableVariable(required = true)
public List<Result> customerAccountContacts;
0

1 Answer 1

1

it's difficult to understand...

But did you try this code :


public static List<Result> getPINPassword(List<Request> requestList) {

        List<Result> resultList = new List<Result>();

        Result response = new Result();
        Result response1 = new Result();

            
        response.errorOcurred = false;
        response.contactName = 'Contact1';
        response.contactRoleType = 'Primary';
        response.decryptedPassword = 'decryptedPassword';
        response.passwordChangeIsRequired = false;
        response.passwordIsSet = true;
        response.hintText = 'hintText';
        resultList.add(response);

            
        response1.contactName = 'Contact2';
        response1.contactRoleType = 'Secondary';
        response1.decryptedPassword = 'decryptedPassword1';
        response1.passwordChangeIsRequired = false;
        response1.passwordIsSet = true;
        response1.hintText = 'hintText';
        resultList.add(response1);

        return resultList;
    }

public class Result {

        @invocableVariable(required=true)
         public boolean errorOcurred;
 
        @InvocableVariable(required=true)
        public String contactName;

        @InvocableVariable(required=true)
        public String contactRoleType;

        @InvocableVariable(required=false)
        public String decryptedPassword;

        @InvocableVariable(required=false)
        public String hintText;

        @InvocableVariable(required=false)
        public Boolean passwordChangeIsRequired;

        @InvocableVariable(required=false)
        public Boolean passwordIsSet;

        public Result() {
            //set defaults
            this.passwordChangeIsRequired = false;
            this.passwordIsSet = false;
            this.errorOccured = false
        }
    }

I think it's for the purpose of testing that you hardcode the returned values in your method and do not use the List input parameters on which you should otherwise iterate in order to build the appropriate list of results to send back to the flow.

1
  • Thanks Chris, this helped a bit.
    – sumchans
    Commented Jan 6, 2023 at 18:06

You must log in to answer this question.

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