You need to sign in to do that
Don't have an account?
Masie
Trigger on a join object not firing.
Hi
Me again- I have written a trigger on a join object to update the one of its parent object based on the other's details.
The two objects are Accounts and Rate Type and the join object is called Company and Rate Type Links. May someone please take a look and let me know where I am going wrong as it is not firing.
trigger UpdateGroupRates on Company_and_RateType_Link__c (after update, after insert)
{
if(trigger.isUpdate)
{
Set<Id> accountIds = new Set<Id>();
Set<Id> ratesIds = new Set<Id>();
for(Company_and_RateType_Link__c tempJ : Trigger.new)
{
accountIds.add(tempJ.Company__c);
ratesIds.add(tempJ.Rate_Type__c);
}
List<Account> AccountList = [Select Id, name, Rate_Type__c, Fixed_Credit_Card_Rate__c, Fixed_Debit_Card_Rate__c from Account where Id IN: accountIds];
List<Rate_Type_del__c> Ratelist = [Select id, Name, Rate_Type__c, Number_Credit_Card_Fee__c, Number_Debit_Card_Fee__c from Rate_Type_del__c where id in: ratesIds];
for(Company_and_RateType_Link__c tempJ : Trigger.new)
{
for(Account tempAcc : AccountList)
{
if(tempJ.Company__c == tempAcc.Id)
{
for(Rate_Type_del__c tempRate : Ratelist)
{
if(tempJ.Rate_Type__c == tempRate.Id )
{
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 AccountList;
}
}
Me again- I have written a trigger on a join object to update the one of its parent object based on the other's details.
The two objects are Accounts and Rate Type and the join object is called Company and Rate Type Links. May someone please take a look and let me know where I am going wrong as it is not firing.
trigger UpdateGroupRates on Company_and_RateType_Link__c (after update, after insert)
{
if(trigger.isUpdate)
{
Set<Id> accountIds = new Set<Id>();
Set<Id> ratesIds = new Set<Id>();
for(Company_and_RateType_Link__c tempJ : Trigger.new)
{
accountIds.add(tempJ.Company__c);
ratesIds.add(tempJ.Rate_Type__c);
}
List<Account> AccountList = [Select Id, name, Rate_Type__c, Fixed_Credit_Card_Rate__c, Fixed_Debit_Card_Rate__c from Account where Id IN: accountIds];
List<Rate_Type_del__c> Ratelist = [Select id, Name, Rate_Type__c, Number_Credit_Card_Fee__c, Number_Debit_Card_Fee__c from Rate_Type_del__c where id in: ratesIds];
for(Company_and_RateType_Link__c tempJ : Trigger.new)
{
for(Account tempAcc : AccountList)
{
if(tempJ.Company__c == tempAcc.Id)
{
for(Rate_Type_del__c tempRate : Ratelist)
{
if(tempJ.Rate_Type__c == tempRate.Id )
{
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 AccountList;
}
}
If this solves your problem, kindly mark it as the best answer.
Thanks,
Vatsal
All Answers
You have added the if condition in the 3rd line "if(trigger.isUpdate)", which ends at the end of the code, so it will work for update only, not for insert.
Its not working for updates as well hence my question.
If this solves your problem, kindly mark it as the best answer.
Thanks,
Vatsal
i am getting a compling error on line 14 where it says the method does not exist or has an incorrect signature Set Id.put(id, sobject) and when I remove the object I still get the same error.
Add below code after 5th line:
May I say that you are the man- it works like a bomb. I clearly need to get some lessons from you.
One other question- its is firing when inserted not when updated- is there anything I can do to fix this.