+ Start a Discussion
Rakhi B 10Rakhi B 10 

account address is change related custome object adress also change using trigger (update))

Sunil_sfcd803Sunil_sfcd803
Hi Rakhi,

Below is trigger.Here Ticket_Details__c is my coustome object which is ahving look up relationship with account and is having Ticket_Address__c which will be updated if account billing address is changed.
trigger updateTicketAddress on Account (after update) {

   if(Trigger.isUpdate){
   Map<id,Account> updateTicket =  new Map<id,Account>();
   
   for (Account acc:Trigger.new){
   
     String oldBillingStreet = Trigger.oldMap.get(acc.Id).BillingStreet;
     String oldBillingCity= Trigger.oldMap.get(acc.Id).BillingCity;
     String oldBillingState= Trigger.oldMap.get(acc.Id).BillingState;
     String oldBillingPostalCode= Trigger.oldMap.get(acc.Id).BillingPostalCode ;
     String oldBillingCountry= Trigger.oldMap.get(acc.Id).BillingCountry;
             
   if(acc.BillingStreet!=oldBillingStreet ||acc.BillingCity!=oldBillingCity||acc.BillingState!=oldBillingState||acc.BillingPostalCode!=oldBillingPostalCode||acc.BillingCountry!=oldBillingCountry){
   updateTicket.put(acc.id,acc);
   }
    
   }
   List<Ticket_Details__c> lTicket =[select id,Account__c,Ticket_Address__c from Ticket_Details__c where Account__c in:updateTicket.KeySet()];
   List<Ticket_Details__c> lTicket2= new List<Ticket_Details__c>();
   For (Ticket_Details__c ticket:lTicket ){
       
       Account acc= updateTicket.get(ticket.Account__c);
       ticket.Ticket_Address__c = acc.BillingStreet +  + 
                                        acc.BillingCity + ','+ 
                                        acc.BillingState + ',' + 
                                        acc.BillingPostalCode + + 
                                        acc.BillingCountry;
                                        
          lTicket2.add(ticket);
   }
   
   update lTicket2;
   
 }


}

Please mark this as solution if this will help you. So that if any one has same issue this post can help