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
MasieMasie 

Multiple Objects in Trigger

Hi lovely people

I need to create a trigger that will update the accounts object based on values in either my rates object or my group rates custom object. I have a trigger to update the account based on the rates object but I would like to have a delimitor that says should there not be a rates id update using the group rate information.

Any assistance with this will be greatly appreciated.
Sagar PareekSagar Pareek
Hi Masie,

As far as i understood your requirement :

You will need two triggers, one on rates object and another one on group rates object.
Both of the triggers will update the account record(s).

Regarding the last line you have written "should there not be a rates id update using the group rate information" , can you explain in more detail what ids you are talking about? salesforce ids?


MasieMasie
Hi Sagar

The group rates is a joining object for accounts and rates so an account record will either have an associated rate or an associated group rate. So I want it to update the account screen based on the what the account has linked to it.
MasieMasie
Hi Sagar or anyone out there :).

I created this trigger to update when a join object- company and rate type link is updated but its not firing, may I ask that you take a look for me and let me know what the problem could be.

trigger UpdateGroupRates on Company_and_RateType_Link__c (before update)
{  
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;
}
      
}