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
shivangi shailesh 8shivangi shailesh 8 

Hi i am getting this issue in my trigger and trigger handler class .Issues are :Invalid loop variable type expected Id was ABI_SFA_Orders_with_Case__c

trigger FetchingDataFromOrder on ABI_SFA_Orders_with_Case__c (before insert,before update) {
      CaseRelatedlistFromOrder handler = new  CaseRelatedlistFromOrder();
      handler.Updateorderlinkdata(Trigger.new);
}    
  Trigger 

Trigger handler class:

public class CaseRelatedlistFromOrder{

    public void Updateorderlinkdata(list<id>listOrders){
           
        
        For(ABI_SFA_Orders_with_Case__c owc :listOrders){
        if(owc.ABI_SFA_Case__c != null && owc.ABI_SFA_Order_Link__c != null){
            listOrders.add(owc.ABI_SFA_Order_Link__c);

        }
        list<ABI_SFA_Order__c> listNewOrders = [select id,ABI_SFA_Accounting_resolution__c,ABI_SFA_Negotiations_Status__c from ABI_SFA_Order__c where id =: listOrders];
        
        
        For(ABI_SFA_Orders_with_Case__c owc2 : listOrders){
            
            for(ABI_SFA_Order__c ord :listNewOrders){
                if(owc2.ABI_SFA_Order_Link__c == ord.id){
                    owc2.ABI_SFA_Accounting_resolution__c= ord.ABI_SFA_Accounting_resolution__c;
                    owc2.ABI_SFA_Negotiations_status__c= ord.ABI_SFA_Negotiations_Status__c;
                    
                    
                }
                
            }
        }
        
    }
    }
}
Maharajan CMaharajan C
Hi Shivangi,

you are using the Trigger.New parameter which is the list of ABI_SFA_Orders_with_Case__c  records not the Ids. 

so change the below line:

 public void Updateorderlinkdata(list<id>listOrders)

to 

public void Updateorderlinkdata(list<ABI_SFA_Orders_with_Case__c > listOrders)

please avoid the multiple for loops and avoid the SOQL inside the for loops.

and also updated your helper class try the below one:

public class CaseRelatedlistFromOrder{

    public void Updateorderlinkdata(list<ABI_SFA_Orders_with_Case__c> listOrders){
           
        set<Id> idSet = new set<Id>();
        For(ABI_SFA_Orders_with_Case__c owc :listOrders){
        if(owc.ABI_SFA_Case__c != null && owc.ABI_SFA_Order_Link__c != null){
            idSet.add(owc.ABI_SFA_Order_Link__c);

        }
        }
        
        if(idSet.size() > 0)
        list<ABI_SFA_Order__c> listNewOrders = [select id,ABI_SFA_Accounting_resolution__c,ABI_SFA_Negotiations_Status__c from ABI_SFA_Order__c where id IN: idSet];
        
        
        if(listNewOrders.size() > 0)
        {
        for(ABI_SFA_Orders_with_Case__c owc2 : listOrders){
            
            for(ABI_SFA_Order__c ord :listNewOrders){
                if(owc2.ABI_SFA_Order_Link__c == ord.id){
                    owc2.ABI_SFA_Accounting_resolution__c= ord.ABI_SFA_Accounting_resolution__c;
                    owc2.ABI_SFA_Negotiations_status__c= ord.ABI_SFA_Negotiations_Status__c;
                    
                    
                }
                
            }
        }
        }
        
    
    }
}

Can you please Let me know if it helps or not!!!

If it helps don't forget to mark this as a best answer!!!


Thanks,
Maharajan.C
shivangi shailesh 8shivangi shailesh 8
Hi ,Thanks for the solution but it is still giving me errors as :
public class CaseRelatedlistFromOrder {
    public void Updateorderlinkdata(list<ABI_SFA_Orders_with_Case__c> listOrders){
           
        set<Id> idSet = new set<Id>();
        For(ABI_SFA_Orders_with_Case__c owc :listOrders){
        if(owc.ABI_SFA_Case__c != null && owc.ABI_SFA_Order_Link__c != null){
            idSet.add(owc.ABI_SFA_Order_Link__c);

        }
        }
        
        if(idSet.size() > 0)
        list<ABI_SFA_Order__c> listNewOrders = [select id,ABI_SFA_Accounting_resolution__c,ABI_SFA_Negotiations_Status__c from ABI_SFA_Order__c where id IN: idSet];
        
        
        if(listNewOrders.size() > 0)
        {
        for(ABI_SFA_Orders_with_Case__c owc2 : listOrders){
            
            for(ABI_SFA_Order__c ord :listNewOrders){
                if(owc2.ABI_SFA_Order_Link__c == ord.id){
                    owc2.ABI_SFA_Accounting_resolution__c= ord.ABI_SFA_Accounting_resolution__c;
                    owc2.ABI_SFA_Negotiations_status__c= ord.ABI_SFA_Negotiations_Status__c;
                    
                    
                }
                
            }
        }
        }
        
    
    }
}
 
trigger FetchingDataFromOrder on ABI_SFA_Orders_with_Case__c (before insert,before update) {
    CaseRelatedlistFromOrder handler = new  CaseRelatedlistFromOrder();
      handler.Updateorderlinkdata(Trigger.new);
}



User-added image
Maharajan CMaharajan C
Hi,

one small update in the code to remove the error in line 16,20

first remove the reference of helper in trigger by comments like below then save the class first by using the below class.

trigger FetchingDataFromOrder on ABI_SFA_Orders_with_Case__c (before insert,before update) { CaseRelatedlistFromOrder handler = new CaseRelatedlistFromOrder(); //handler.Updateorderlinkdata(Trigger.new); ///// once the class is saved then enable this line
}


public class CaseRelatedlistFromOrder {
    public void Updateorderlinkdata(list<ABI_SFA_Orders_with_Case__c> listOrders){
           
        set<Id> idSet = new set<Id>();
        list<ABI_SFA_Order__c> listNewOrders = new List<ABI_SFA_Order__c>();
        For(ABI_SFA_Orders_with_Case__c owc :listOrders){
        if(owc.ABI_SFA_Case__c != null && owc.ABI_SFA_Order_Link__c != null){
            idSet.add(owc.ABI_SFA_Order_Link__c);

        }
        }
        
        if(idSet.size() > 0)
        listNewOrders = [select id,ABI_SFA_Accounting_resolution__c,ABI_SFA_Negotiations_Status__c from ABI_SFA_Order__c where id IN: idSet];
        
        
        if(listNewOrders.size() > 0)
        {
        for(ABI_SFA_Orders_with_Case__c owc2 : listOrders){
            
            for(ABI_SFA_Order__c ord :listNewOrders){
                if(owc2.ABI_SFA_Order_Link__c == ord.id){
                    owc2.ABI_SFA_Accounting_resolution__c= ord.ABI_SFA_Accounting_resolution__c;
                    owc2.ABI_SFA_Negotiations_status__c= ord.ABI_SFA_Negotiations_Status__c;
                    
                    
                }
                
            }
        }
        }
        
    
    }
}

Can you please Let me know if it helps or not!!!

If it helps don't forget to mark this as a best answer!!!


Thanks,
Maharajan.C