• Harish Nalla
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
Hi

May someone please help, I have an object called the rebate that has a lookup relationship to the account object. I want when a field is updated on the account object a field should also be updated on the rebate object but I am having a problem with this trigger.

trigger updateStartDate on Rebates__c (after insert, after update,before update){

Set<Id> accountIds = new Set<Id>();
   
    for(Rebates__c reb :trigger.new){
        accountIds.add(reb.Company__c);
}

    Map <ID,Account> updateAccounts = new Map<ID,Account>([Select id, Date_Installed__c from Account where id IN: AccountIds]);{
                                                 
for(Rebates__c reb :trigger.new){
accountIds.add(reb.Company__c);

       if(reb.From_Install_Date__c == true && updateAccounts.get(reb.Company__c).Date_Installed__c != null){

    if(reb.Product__c == '1t200000024Dtm')

{
                reb.Start_Date__c = reb.First_Day_of_the_Month__c;
   
    accountIds.update(reb);

}

else
{

   reb.Start_Date__c = reb.Install_Date__c;
    accountIds.update(reb);

       }
           try
              
           {
               update accountIds;
           }
           catch (system.DmlException e)
           {
               system.debug (e);
           }

   }
}
}
}
  • August 19, 2014
  • Like
  • 0