You need to sign in to do that
Don't have an account?

Trigger to update contact email when account email is updated
Hi Team,
I am trying to write a triiger when an account email is updated i want to update contact email as well.
can you help me in achevie this from trigger .
trigger accountemailupdated on account(before insert,before update){
List<account> emailnew = new List<account>();
set<id> idvalue = new set<id>();
{
for(account a : trigger.new){
idvalue.add(a);
}
emailnew = [select id,name,email (select id,email from contacts) form account where account id in:idvalue]
for(contacts c :emailnew.accountid){
contacts con = new contacts();
if(emailnew.accountid==con.accountid)
{
con.email = emailnew.email;
}
update emailnew;
}
I am trying to write a triiger when an account email is updated i want to update contact email as well.
can you help me in achevie this from trigger .
trigger accountemailupdated on account(before insert,before update){
List<account> emailnew = new List<account>();
set<id> idvalue = new set<id>();
{
for(account a : trigger.new){
idvalue.add(a);
}
emailnew = [select id,name,email (select id,email from contacts) form account where account id in:idvalue]
for(contacts c :emailnew.accountid){
contacts con = new contacts();
if(emailnew.accountid==con.accountid)
{
con.email = emailnew.email;
}
update emailnew;
}
What is the challenge you are facing with the code you provided?
Related:https://salesforce.stackexchange.com/questions/117600/trigger-on-account-to-update-contactwhenever-account-billingaddress-is-updated
Hi Vijay,
Please Find The Solution. Trigger to update contact email when account email is updated.
Please Let me know it is working or not.
Please mark best answer so that other people would take reference from it.
Thanks
Please Find The Solution. Trigger to update contact email when account email is updated.
Note : Please check any other triggers r not active when updating code this code
trigger testscenario3 on Account (after update)
{
List < Account > accList=[SELECT id,email__c,(SELECT id,email FROM contacts) FROM Account WHERE id IN:trigger.new];
List < contact > conList = new List < contact >();
for(Account acc: accList)
{
if(acc.email__c != null && acc.contacts.size() > 0 )
{
for(contact con : acc.contacts)
{
con.email = acc.Email__c;
conList.add(con);
}
}
}
update conList;
}
Please Let me know it is working or not.
Please mark best answer so that other people would take reference from it.
Thanks