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
raju p 4raju p 4 

Update account phone number by contact phone number by account phone number on before update, it is possible or

Update account phone number by contact phone number  by account phone number on before update, it is possible or not,
 i am trying using berfore update with map, i am not geting 

// update AccountPHONE by CONTACT
   public Class BeoreupdateAccountPhone{
       public static void beforeupdate(map<id,contact>newmap,map<id,contact>oldmap){
       
        set<id> ids= new set<id>();
       for(id key:oldmap.keyset()){
         contact n1= newmap.get(key);
         contact o1= oldmap.get(key);
             ids.add(key);
             
             list<account> ac= new list<account>();
             list<account> acc=[select phone,(select phone from contacts) from account where id=:ids];
                 for(account a:acc){
                    for(contact c:a.contacts){
                       if(a.phone!= c.phone){
                       a.phone= c.phone;
                          // acc.add((c.phone).a.contacts);
                          acc.add(a);
                           }
                           }
                       }
                       update acc;
                       }
                         }}
Gurpreet Singh PanesarGurpreet Singh Panesar
Hi Raju,
You should use Trigger There
trigger AccountPhone on Contact (after Insert, before Update) {
    
    List<Account> accListUpdate = new List<Account>();
    
    Map<Id,String> accPhoneMap = new Map<Id,String>();

            for(Contact con:Trigger.New) {
                accPhoneMap.put(con.AccountId,con.Phone);  
                System.debug('here'+accPhoneMap);   
            }
            
            List<Account> accList = [Select ID,Phone FROM Account WHERE ID IN : accPhoneMap.keySet()];
                
            for(Account acc : accList) {
                
                acc.Phone = accPhoneMap.get(acc.Id);
                accListUpdate.add(acc);
                System.debug('inside for'+accListUpdate);
            }               
            if(accListUpdate.size()>0) {
                update accListUpdate;
            }
}
It will update your Account's phone number with Contact's phone number.
I think this is same as your requirement.
Now you have an idea to update Account field by related Contact's now you can mould this logic as your need.
Thanks,
Raju