+ Start a Discussion
MasieMasie 

Trigger not firing- please help

Hello Everyone

Please may I have some help, I have this trigger and it is not firing. Can someone please take a look for me.

trigger updateRates on Rate_Type_del__c (after update) {
  
Set<Id> RateTypedelids = new Set<Id>();
    list <Account> newratelist = new list <Account>();
   
    for(Rate_Type_del__c rate:trigger.new){
        RateTypedelids.add(rate.id);
}
    List <Account> ratelist =[Select Id, name, Rate_Type__c, Fixed_Credit_Card_Rate__c, Fixed_Debit_Card_Rate__c from Account where Id in:RateTypedelids];
                                                 
      for(Rate_Type_del__c temprate:trigger.new){
      for(Account tempacc:ratelist){
      if(temprate.Company_del__c == tempacc.id && temprate.RecordType.Name == 'SureSwipe Base Rates' && temprate.Status__c == 'Active'){
{
    tempacc.Rate_Type__c = temprate.Rate_Type__c;
    tempacc.Fixed_Credit_Card_Rate__c = temprate.Number_Credit_Card_Fee__c;
    tempacc.Fixed_Debit_Card_Rate__c = temprate.Number_Debit_Card_Fee__c;
}
          }
        update newratelist;
    }
}

}
Best Answer chosen by Masie
Vatsal KothariVatsal Kothari
Replace 27th line with below code:

update accMap.values();
If this solves your problem, kindly mark it as the best answer.

Thanks,
Vatsal

All Answers

Ilene JonesIlene Jones
Hi Maise, 

The first thing I see is that you are trying to run a trigger on an object that has been marked for deletion.  You may need to rename your object, and the references to it from Rate_Type_del__c to Rate_Type__c in order to get that trigger to run.  
Vatsal KothariVatsal Kothari
Hi,

for(Rate_Type_del__c rate:trigger.new){
		RateTypedelids.add(rate.id);
	}

In above code you are creating Set of Id with "Rate_Type_del__c" Object's Id and Querying it on account object i.e
Select Id, name, Rate_Type__c, Fixed_Credit_Card_Rate__c, Fixed_Debit_Card_Rate__c from Account where Id in:RateTypedelids

so it should be like :
for(Rate_Type_del__c rate:trigger.new){
		RateTypedelids.add(rate.AccountLookupId);
	}
Replace AccountLookupId with API name of the field and remove Update statement from for loop.

If this solves your problem, kindly mark it as the best answer.

Thanks,
Vatsal

MasieMasie
Hi Vatsal

I have done as recommended and its still not working. What I want to do is up[date the account screen with the details on the rate object. 

trigger updateRates on Rate_Type_del__c (after update){
  
Set<Id> RateTypedelids = new Set<Id>();
    list <Account> newratelist = new list <Account>();
   
    for(Rate_Type_del__c rate:trigger.new){
        RateTypedelids.add(rate.Company_del__c);
}
    List <Account> ratelist =[Select Id, name, Rate_Type__c, Fixed_Credit_Card_Rate__c, Fixed_Debit_Card_Rate__c from Account where Id in:RateTypedelids];
                                                 
      for(Rate_Type_del__c temprate:trigger.new){
      for(Account tempacc:ratelist){
          if(temprate.Company_del__c == tempacc.id &&temprate.RecordType.Name == 'SureSwipe Base Rates' &&temprate.Status__c == 'Active'){
{
    tempacc.Rate_Type__c = temprate.Rate_Type__c;
    tempacc.Fixed_Credit_Card_Rate__c = temprate.Number_Credit_Card_Fee__c;
    tempacc.Fixed_Debit_Card_Rate__c = temprate.Number_Debit_Card_Fee__c;
}
          }
      }
      }
}
MasieMasie
Hi Ilene

The object was deleted then undeleted hence the _del on the name.
Ilene JonesIlene Jones
n your second code dump, I do not see a specific update call out, and your trigger variable is rate, which means the DML is not being told to update the list.  You can update it in a few ways, but this one may be the easiest, based on your current code set.

trigger updateRates on Rate_Type_del__c (after update){
 
    Set<Id> RateTypedelids = new Set<Id>();
    list <Account> newratelist = new list <Account>();
    List<Account> accountList = new List<Account>();
  
    for(Rate_Type_del__c rate : trigger.new){
         RateTypedelids.add(rate.Company_del__c);
    }

    List <Account> ratelist =[Select Id, name, Rate_Type__c, Fixed_Credit_Card_Rate__c, Fixed_Debit_Card_Rate__c from Account where Id in:RateTypedelids];
                                                
    for(temprate: trigger.new){

        for(Account tempacc:ratelist){

            if(temprate.Company_del__c == tempacc.id &&
               temprate.RecordType.Name == 'SureSwipe Base Rates' &&
               temprate.Status__c == 'Active'){

                tempacc.Rate_Type__c = temprate.Rate_Type__c;
                tempacc.Fixed_Credit_Card_Rate__c = temprate.Number_Credit_Card_Fee__c;
                tempacc.Fixed_Debit_Card_Rate__c = temprate.Number_Debit_Card_Fee__c;

                accountList.add(tempacc);
            }
        }
    }
    update accountList;
}
Vatsal KothariVatsal Kothari
Hi Masie,

Below is the updated code:

trigger updateRates on Rate_Type_del__c (after update){
 
    Set<Id> RateTypedelids = new Set<Id>();
    Map<Id,Account> accMap = new Map<Id,Account>();
	
    for(Rate_Type_del__c rate : trigger.new){
		if(rate.Company_del__c != null){
			RateTypedelids.add(rate.Company_del__c);
		}
    }

    for(Account tempacc: [Select Id, name, Rate_Type__c, Fixed_Credit_Card_Rate__c, Fixed_Debit_Card_Rate__c from Account where Id IN: RateTypedelids]){
		if(tempacc.Id != null){
			accMap.put(tempacc.Id,tempacc);
		}
	}
	
    for(Rate_Type_del__c temprate: trigger.new){

		if(accMap.containsKey(temprate.Company_del__c) && temprate.RecordType.Name == 'SureSwipe Base Rates' && temprate.Status__c == 'Active'){
			accMap.get(temprate.Company_del__c).Rate_Type__c = temprate.Rate_Type__c;
			accMap.get(temprate.Company_del__c).Fixed_Credit_Card_Rate__c = temprate.Number_Credit_Card_Fee__c;
			accMap.get(temprate.Company_del__c).Fixed_Debit_Card_Rate__c = temprate.Number_Debit_Card_Fee__c;
		}
	}
	if(!accMap.isEmpty()){
		update accMap;
	}
}

If this solves your problem, kindly mark it as the best answer.

Thanks,
Vatsal
MasieMasie
Thanks Vatsal- I am getting the following error DML requires SObject or SObject list type: MAP&lt;Id,Account&gt;
Vatsal KothariVatsal Kothari
Replace 27th line with below code:

update accMap.values();
If this solves your problem, kindly mark it as the best answer.

Thanks,
Vatsal

This was selected as the best answer
MasieMasie
Thanks Vatsal-  the code worked. The problem is the record type reference as soon as I removed that it was fab.