You need to sign in to do that
Don't have an account?
CodeBeginner
Hi team, can you help me with below code iam new to customization just practing things. Please correct my code
I am trying to write a trigger for acount field update when coresponding contact field in updated. Please help me here the code is not saving
Trigger FieldupdateOnAccount on Contact(after insert, after update){
set<id> conset = new set<id>();
for(Contact c: trigger.new){
conset.add(c.id);
}
list<Account> Lstacc = [select Name, Phone(select Name, Phone from Contacts) from Account where Contactid in: conset];
List<Account> Acclist = new List<Account>();
if(Lstacc.size()>0 && Trigger.newMap.get(Id).Phone != Trigger.oldMap.get(Id).Phone){
for(Account acc :Lstacc){
for(Contact c: acc.Contacts){
acc.Phone = c.Phone;
Acclist.add(acc);
}
}
Update Acclist;
}
}
Trigger FieldupdateOnAccount on Contact(after insert, after update){
set<id> conset = new set<id>();
for(Contact c: trigger.new){
conset.add(c.id);
}
list<Account> Lstacc = [select Name, Phone(select Name, Phone from Contacts) from Account where Contactid in: conset];
List<Account> Acclist = new List<Account>();
if(Lstacc.size()>0 && Trigger.newMap.get(Id).Phone != Trigger.oldMap.get(Id).Phone){
for(Account acc :Lstacc){
for(Contact c: acc.Contacts){
acc.Phone = c.Phone;
Acclist.add(acc);
}
}
Update Acclist;
}
}
You can try this Regards,
Soyab
All Answers
You can try this Regards,
Soyab
It worked fine, Thanks for the code.