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
sai kumar 49sai kumar 49 

write a trigger on how to create a contact while we are creating a account and when we perform update on account the contact fields are also updated automatically..

ManojjenaManojjena
Hi Sai ,

Try with below code it will help !
trigger ContactManipulation on Account (after insert,after update ){
  Map<Id,Account> accMap=new Map<Id,Account>();
  List<Contact> conListoInsertUpdate=new List<Contact>();
   if(Trigger.isInsert){
    for(Account acc :Trigger.new){
       Contact con=new contact();
       con.LastName=acc.Name;
       //Add if any additional fields need to map from Account
       conListoInsertUpdate.add(con);
    }
 }if(Trigger.isUpdate){
    for(Account acc :Trigger.new){
      accMap.put(acc.Id,acc);
    }
    for(Contact con : [SELECT Id,LastName,AccountId FROM Contact WHERE AccountId IN : accMap.keySet() ]){
      con.lastName=accMap.get(con.AccountId).Name;
      conListoInsertUpdate.add(con);
    }
  }
  try{
      upsert conListoInsertUpdate;
    }catch(DmlException de ){
      System.debug(de);
    }
}
Thanks
Manoj