+ Start a Discussion
Kelsey ShannonKelsey Shannon 

Invalid loop variable type expected Approver__c was list

I'm struggling with finishing off this piece of code, anyone have a suggestion? Its returning an error at line 22: invalid loop variable type expected Approver__c was List
public class Invocable_eG_ProductSBUSearch
{
	@InvocableMethod(label='Find Valid Approvers' description ='Searchs the database for matches in SEA Approvers')
    //productSBUSearch comes from the flow and contains the eGreensheet ID and Tier selected concatenated
    public static List<List<Approver__c>> approverIds (List<String> productSBUSearch){
      	
 		// One sObject per search eGreensheet record (bulkify)
		List<List<SObject>> wrapsApprovers = new List<List<SObject>>();
		for (String searchTerm : productSBUSearch) {
			wrapsApprovers.add(new List<SObject>());
			}
        
        //Pull eGreensheet Product SBU into a list
        List<Workflow_Details__c> eGs = [SELECT Product_SBU_List__c FROM Workflow_Details__c where Id in :productSBUSearch];
        
        //Pull all possible approvers
        List<Approver__c> possibleApprovers = [SELECT Product_SBU__c, Tier__c FROM Approver__c WHERE Active__c = true and Approver_type__c = 'Product Approver' and Product_SBU__c != null and Tier__c in :productSBUSearch];
        system.debug('wwwwwwwwwwwww' + possibleApprovers);
        
		//Add all approvers who qualify to the final list
		//WFList[0].Product_SBU__c.contains(Alist[j].Product_SBU__c)
		for (List<SObject> listOfApprovers : possibleApprovers){
			for (SObject returnList : listOfApprovers) {
            //Query for matches  
                if(eGs[0].Product_SBU_List__c.contains(possibleApprovers[0].Product_SBU__c)){
			//Return fields to the flow
			wrapsApprovers[0].add(returnList);
                }
			}
		}        
        return wrapsApprovers;   
 }
}
Best Answer chosen by Kelsey Shannon
Steven NsubugaSteven Nsubuga
public class Invocable_eG_ProductSBUSearch
{
	@InvocableMethod(label='Find Valid Approvers' description ='Searchs the database for matches in SEA Approvers')
    //productSBUSearch comes from the flow and contains the eGreensheet ID and Tier selected concatenated
    public static List<List<Approver__c>> approverIds (List<String> productSBUSearch){
      	
 		// One sObject per search eGreensheet record (bulkify)
		List<List<SObject>> wrapsApprovers = new List<List<SObject>>();
		for (String searchTerm : productSBUSearch) {
			wrapsApprovers.add(new List<SObject>());
			}
        
        //Pull eGreensheet Product SBU into a list
        List<Workflow_Details__c> eGs = [SELECT Product_SBU_List__c FROM Workflow_Details__c where Id in :productSBUSearch];
        
        //Pull all possible approvers
        List<Approver__c> possibleApprovers = [SELECT Product_SBU__c, Tier__c FROM Approver__c WHERE Active__c = true and Approver_type__c = 'Product Approver' and Product_SBU__c != null and Tier__c in :productSBUSearch];
        system.debug('wwwwwwwwwwwww' + possibleApprovers);
        
		//Add all approvers who qualify to the final list
		//WFList[0].Product_SBU__c.contains(Alist[j].Product_SBU__c)
		for (SObject returnList : possibleApprovers){
            //Query for matches  
                if(eGs[0].Product_SBU_List__c.contains(possibleApprovers[0].Product_SBU__c)){
			//Return fields to the flow
			wrapsApprovers[0].add(returnList);
                }
		}        
        return wrapsApprovers;   
 }
}

Try that

All Answers

Steven NsubugaSteven Nsubuga
public class Invocable_eG_ProductSBUSearch
{
	@InvocableMethod(label='Find Valid Approvers' description ='Searchs the database for matches in SEA Approvers')
    //productSBUSearch comes from the flow and contains the eGreensheet ID and Tier selected concatenated
    public static List<List<Approver__c>> approverIds (List<String> productSBUSearch){
      	
 		// One sObject per search eGreensheet record (bulkify)
		List<List<SObject>> wrapsApprovers = new List<List<SObject>>();
		for (String searchTerm : productSBUSearch) {
			wrapsApprovers.add(new List<SObject>());
			}
        
        //Pull eGreensheet Product SBU into a list
        List<Workflow_Details__c> eGs = [SELECT Product_SBU_List__c FROM Workflow_Details__c where Id in :productSBUSearch];
        
        //Pull all possible approvers
        List<Approver__c> possibleApprovers = [SELECT Product_SBU__c, Tier__c FROM Approver__c WHERE Active__c = true and Approver_type__c = 'Product Approver' and Product_SBU__c != null and Tier__c in :productSBUSearch];
        system.debug('wwwwwwwwwwwww' + possibleApprovers);
        
		//Add all approvers who qualify to the final list
		//WFList[0].Product_SBU__c.contains(Alist[j].Product_SBU__c)
		for (SObject returnList : possibleApprovers){
            //Query for matches  
                if(eGs[0].Product_SBU_List__c.contains(possibleApprovers[0].Product_SBU__c)){
			//Return fields to the flow
			wrapsApprovers[0].add(returnList);
                }
		}        
        return wrapsApprovers;   
 }
}

Try that
This was selected as the best answer
Kelsey ShannonKelsey Shannon
That worked, thanks! I don't know why I thought I had to do a subloop to get it into a list of lists