You need to sign in to do that
Don't have an account?
raju p 4
I have little dought in trigger can we update account phone number by contact phone number >ON Beffore update,,please focus on this, i am using map i am not getting need know for learning purpose
I have little dought in trigger can we update account phone number by contact phone number >ON Beffore update,,please focus on this, i am using map i am not getting need know for learning purpose
i know after it is possible please brifly explain me,
// 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).contacts);
}
}
}
update acc;
}
}}
i know after it is possible please brifly explain me,
// 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).contacts);
}
}
}
update acc;
}
}}
I have posted you a logic which will work on After Insert and Before Update, you should copy and paste this logic without modifying in your org and will work as your requirement.
It will update Account Phone which is updated on Contact.
Thanks,
Raju