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
Abhishek PurohitAbhishek Purohit 

Now here is the question..I need to create an after update.Also trying for an Helper class Kindly guide.

trigger ShippingBillingAddress on Account (before insert,before update,after insert,after update) {
 if(Trigger.isBefore)
    {
    for(Account accountList:Trigger.New)
     {
     if(Trigger.isInsert)
     
      {
     
     accountList.ShippingStreet=accountList.BillingStreet;
     accountList.ShippingCountry=accountList.BillingCountry;
     accountList.ShippingCity=accountList.BillingCity;
     accountList.ShippingState=accountList.BillingState;
     }
    
      if(Trigger.isUpdate)
     { 
      accountList.ShippingStreet=accountList.BillingStreet;
     accountList.ShippingCountry=accountList.BillingCountry;
     accountList.ShippingCity=accountList.BillingCity;
     accountList.ShippingState=accountList.BillingState;
      }
      
      
     }
    
      
       
       
       
    } 

 if(Trigger.IsAfter)
   {
   List<Contact> contactCreate=new List<Contact>();
   for(Account accountList2:Trigger.New)
    {
    if(Trigger.IsInsert)
      {
    Contact contactrecordCreate=new Contact();
      contactrecordCreate.accountId=accountList2.Id;
      contactrecordCreate.LastName=accountList2.Name;
      contactrecordCreate.Phone=accountList2.Phone;
      
      contactCreate.add(contactrecordCreate);
     }
     
  insert contactCreate;
  
  }
  }
  

    

}

 
Best Answer chosen by Abhishek Purohit
Abhishek PurohitAbhishek Purohit
trigger ShippingBillingAddress on Account (before insert,before update,after insert,after update) {
 if(Trigger.isBefore)
    {
    for(Account accountObject:Trigger.New)
          {
          if(Trigger.isInsert || Trigger.isUpdate){
     
                 accountObject.ShippingStreet=accountObject.BillingStreet;
                 accountObject.ShippingCountry=accountObject.BillingCountry;
                 accountObject.ShippingCity=accountObject.BillingCity;
                 accountObject.ShippingState=accountObject.BillingState;
                 }
          }
    
      
     } 

 
  if(Trigger.isAfter)
   {
    if(Trigger.isUpdate)
     {
      Set<Id> setOfAccountIds=new Set<Id>();
       for(Account account:Trigger.New)
           {
             setOfAccountIds.add(account.id);
           }       
            List<Contact> listOfContact=new List<Contact>([Select Id,AccountId FROM Contact WHERE AccountId IN:setOfAccountIds]);
            List<Contact> listOfUpdatedContact=new List<Contact>();
             
             for(Account accountOfObject:Trigger.New)
             {
              for(Contact contactOfObject:listOfContact)
               {
                contactOfObject.Phone=accountOfObject.Phone;
             
                listOfUpdatedContact.add(contactOfObject);
               }
             } 
       update listOfUpdatedContact;
      
     }
   }
    
}

Done with it...can anyone tell me about it's helper class? 

All Answers

Amit Chaudhary 8Amit Chaudhary 8
Abhishek PurohitAbhishek Purohit
trigger ShippingBillingAddress on Account (before insert,before update,after insert,after update) {
 if(Trigger.isBefore)
    {
    for(Account accountObject:Trigger.New)
          {
          if(Trigger.isInsert || Trigger.isUpdate){
     
                 accountObject.ShippingStreet=accountObject.BillingStreet;
                 accountObject.ShippingCountry=accountObject.BillingCountry;
                 accountObject.ShippingCity=accountObject.BillingCity;
                 accountObject.ShippingState=accountObject.BillingState;
                 }
          }
    
      
     } 

 
  if(Trigger.isAfter)
   {
    if(Trigger.isUpdate)
     {
      Set<Id> setOfAccountIds=new Set<Id>();
       for(Account account:Trigger.New)
           {
             setOfAccountIds.add(account.id);
           }       
            List<Contact> listOfContact=new List<Contact>([Select Id,AccountId FROM Contact WHERE AccountId IN:setOfAccountIds]);
            List<Contact> listOfUpdatedContact=new List<Contact>();
             
             for(Account accountOfObject:Trigger.New)
             {
              for(Contact contactOfObject:listOfContact)
               {
                contactOfObject.Phone=accountOfObject.Phone;
             
                listOfUpdatedContact.add(contactOfObject);
               }
             } 
       update listOfUpdatedContact;
      
     }
   }
    
}

Done with it...can anyone tell me about it's helper class? 
This was selected as the best answer