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
anji punyamanthulaanji punyamanthula 

I want to invoke update Class of Map in trigger, can any one let me know how to do that

I want to invoke  update Class of Map in trigger, can any one let me know how to do  I'm attaching my controller below

public class Map_Acc_Con_upp_Ex1 {
    public Static void Afterupdate(Map<Id,Account> accs){
        List<Account> accounts=accs.values();
        Set<Id> acids=accs.keyset();
        List<Contact> contacts=new List<Contact>();
        List<contact> cons=[select LastName,phone,AccountId from Contact where Accountid in:acids];
        for(Contact c:cons){
            c.phone=c.Account.Phone;
            contacts.add(c);
        }
        update contacts;
    }

}
Raj VakatiRaj Vakati
Can you please explain what is your requirement? I don't understand it properly  
Raj VakatiRaj Vakati
Do it as below ..create a trigger with below code 

 
trigger Acc on Account (after update) {
    Map_Acc_Con_upp_Ex1.Afterupdate(Trigger.newMap);
}

Class is here 
public class Map_Acc_Con_upp_Ex1 {
    public Static void Afterupdate(Map<Id,Account> accs){
        List<Account> accounts=accs.values();
        Set<Id> acids=accs.keyset();
        List<Contact> contacts=new List<Contact>();
        List<contact> cons=[select LastName,phone,AccountId from Contact where Accountid in:acids];
        for(Contact c:cons){
            c.phone=c.Account.Phone;
            contacts.add(c);
        }
        update contacts;
    }

}