For a web callout I have an array of integers that I'd like to pass into a method parameter. So if any of the array elements is true, then I'd like to assign it to the integer variable custId (since I can't pass more than one value into the custId field). Is there a way to do this way in apex?

        public static Set<String> getListOutBoundRecords(DateTime endDate, Integer custid ){ 
       Customer cod = new Customer(); 
       Authentication req = new Authentication();

       Map<Integer, Integer> vars = new Map<Integer, Integer>();
            vars.put(509684,1 );//Customer 1
            vars.put(408918,2 );//Customer 2
            vars.put(519513,3 );//Customer 3
            vars.put(414399, 4);//Customer 4
            vars.put(498097,5 );//Customer 5

            for(Integer i:vars.values() ){
                if(i == 1){
                custid  = 10;
                else if(i == 2){
               custid   =  20;
                 else if(i == 3){
               custid  = 30;
                else if(i == 4){
              custid   =  40;
                else if(i == 5){
               custid   =  50; 

    req.CustomerId = custid; 


1 Answer 1


I'm not sure if I've understood your question fully, and am struggling to read the sample provided, but no dynamic variables in Apex aren't possible as it's strongly-typed. There's a good description in this response to another question on this very site.

  • Sorry I added additional code. Essentially I'm looking to see if I can loop through an array of integers and if the condition is true for that particular integer element, then I'd assign it to the req.CustomerId variable.
    – AL 600
    Dec 4, 2019 at 12:55

You must log in to answer this question.

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