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
Somasundaram SubramanianSomasundaram Subramanian 

IN operator must be used with an iterable expression at line

why am getting IN operator must be used with an iterable expression at line 

for(pse__Milestone__c ms : mapMilestone.values()){
            if(mapMilestoneRREVA.containsKey(ms.Id) && ms.Budget__c != null){
                set<Id> tempEVAIds = new set<Id>();
                tempEVAIds.addAll(mapMilestoneRREVA.get(ms.Id));
                if(mapBudgetRREVA.containsKey(ms.Budget__c)) {
                    tempEVAIds.addAll(mapBudgetRREVA.get(ms.Budget__c));
                }
                mapBudgetRREVA.put(ms.Budget__c, tempEVAIds);
            }
        }
        system.debug('total mapBudgetRREVA mappings:'+mapBudgetRREVA.size()+' : '+mapBudgetRREVA);  

     map<Id,pse__Est_Vs_Actuals__c> mapEVA = new map<Id,pse__Est_Vs_Actuals__c>([select Id,pse__Project__c,pse__Estimated_Hours__c,pse__Scheduled_Bill_Rate__c,
        pse__Start_Date__c,pse__End_Date__c,pse__Actual_Hours__c,pse__Actual_Billable_Amount__c, pse__Assignment__c from pse__Est_Vs_Actuals__c where pse__Time_Period_Type__c IN: TimePeriodType and  pse__Assignment__r.pse__Milestone__r.Budget__c IN: mapBudgetRREVA
         and ((pse__Start_Date__c >=: M_SWDate and pse__Estimated_Hours__c > 0) or (pse__End_Date__c <: M_EWDate and pse__Actual_Hours__c >0))]);


        
 
AshwiniAshwini (Salesforce Developers) 
Hi @Somasundaram Subramanian,

The error message "IN operator must be used with an iterable expression"  occurs when you try to use the IN operator in a SOQL query with an expression that is not iterable.

In your code, you are trying to use the IN operator with both TimePeriodType and mapBudgetRREVA.

Ensure that TimePeriodType is an iterable collection, such as a List or Set. If it's not iterable, you'll encounter this error. You can convert it to a List or Set.
 
pse__Assignment__r.pse__Milestone__r.Budget__c IN: mapBudgetRREVA

The above line depends on mapBudgetRREVA, which appears to be a Map of Id to Set<Id>.
The IN operator requires a collection type (List, Set) on the right side of the operator, not a Map. You need to extract the values from the Map before using them in the query.

Related: https://salesforce.stackexchange.com/questions/91776/in-operator-must-be-used-with-an-iterable-expression-for-loop
https://www.youtube.com/watch?v=MPk4hIGmDZA 


If this information helps, please mark the answer as best. Thank you

 
Somasundaram SubramanianSomasundaram Subramanian
Hi
Thanks for your reply i want to reduce the number of records in the collection if i give below will it consider ? it saved the code but will it thorugh error when i execute 
pse__Assignment__r.pse__Milestone__r.Budget__r.CreatedDate >: lastYearDate 




map<Id,pse__Est_Vs_Actuals__c> mapEVA = new map<Id,pse__Est_Vs_Actuals__c>([select Id,pse__Project__c,pse__Estimated_Hours__c,pse__Scheduled_Bill_Rate__c,
        pse__Start_Date__c,pse__End_Date__c,pse__Actual_Hours__c,pse__Actual_Billable_Amount__c, pse__Assignment__c from pse__Est_Vs_Actuals__c where pse__Time_Period_Type__c IN: TimePeriodType 
        and pse__Project__c IN: projects and pse__Assignment__r.pse__Milestone__r.Budget__r.CreatedDate >: lastYearDate and ((pse__Start_Date__c >=: M_SWDate and pse__Estimated_Hours__c > 0) or (pse__End_Date__c <: M_EWDate and pse__Actual_Hours__c >0))]);
AshwiniAshwini (Salesforce Developers) 
Hi @Somasundaram Subramanian 

 "pse__Assignment__r.pse__Milestone__r.Budget__r.CreatedDate >: lastYearDate " in your query looks correct and  should not throw an error if lastYearDate is correctly defined with a valid date value. It filters records where the CreatedDate of the related Budget__c object is greater than lastYearDate.

To avoid errors, make sure that this query is executed within an appropriate context where all the variables and fields used in the query are accessible and valid.

If this information helps, please mark the answer as best. Thank you