+ Start a Discussion
divey sainidivey saini 

Compile Error on Trigger

Getting the following error for the trigger below:

Error: Compile Error: Invalid bind expression type of Bank__c for Id field of SObject Customer__c at line 3 column 57 (IN)

trigger BankT on Bank__c (after insert, before update) {
List<Customer__c> CustwithOpps = 
[SELECT ID,Name,Region__c FROM Customer__c WHERE ID IN :Trigger.New];

for(Bank__c a : CustwithOpps) {
Customer__c [] relatedOpps =a.Customer__c;
  } 
}
Best Answer chosen by divey saini
Krishna SambarajuKrishna Sambaraju
Trigger.New gives a list of Bank__c records that are getting inserted or updated, so it is trying to query the Customer__c object with the IDs of the Bank__c object, so it is throwing error. Here is how you can do it.
trigger BankT on Bank__c (after insert, before update) {
    
    Set<Id> customerIds = new Set<Id>();
    for (Bank__c b : Trigger.new)
    {
        customerIds.add(b.Customer__c);//Change it as per your customer id field on the Bank__c object.
    }
    List<Customer__c> CustwithOpps = new List<Customer__c>();
    if (customerIds.size() > 0)
    {
        //This is a list of customers. There are no opps in it.
        CustwithOpps = [SELECT ID,Name,Region__c FROM Customer__c WHERE ID IN :customerIds]; 
        //do your logic with this list.
    }
}
Hope this helps.