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
ccazzccazz 

Invocable Variable not recognized

I am trying to do the following:
Call Apex from a Process or Flow (Invocable Method),
Make an HTTP Callout (can't do this from invocable method so using a queueable class)

I have been using these examples to write the code related to invocable variables:
1. https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_InvocableVariable.htm
2. https://developer.salesforce.com/forums/?id=9060G0000005nusQAA

Here is what I have:
public class EnqueueCallout {

    @InvocableMethod(label='Enroll in XYZ Program' )
    public static void queueCallout(List<FlowInputs> calloutvars) {
        string card = calloutvars.cardnum;
        string offer = calloutvars.offerid;
//this calls the queueable class and sends the variables...this part works fine when using the execute command in the execute anonymous apex window.
        ID jobID = System.enqueueJob(new SendCallout(card, offer));
    }
    //input details that come into apex from flow
    public class FlowInputs {
        @InvocableVariable(required=true)
        public string cardnum;
        
        @InvocableVariable(required=true)
        public string offerid;
    }
}

but I am getting the error "Error: Compile Error: Variable does not exist: cardnum at line 5 column 35"
Best Answer chosen by ccazz
AmarpreetAmarpreet
Hi,

Use this:
string card = calloutvars[0].cardnum;
string offer = calloutvars[0].offerid;

OR, iterate "calloutvars" in for each loop.
for(FlowInputs fi: calloutvars){
            string card = fi.cardnum;
            string offer = fi.offerid;
        }

All Answers

AmarpreetAmarpreet
Hi,

Use this:
string card = calloutvars[0].cardnum;
string offer = calloutvars[0].offerid;

OR, iterate "calloutvars" in for each loop.
for(FlowInputs fi: calloutvars){
            string card = fi.cardnum;
            string offer = fi.offerid;
        }
This was selected as the best answer
ccazzccazz
Thanks @Amarpreet!