You need to sign in to do that
Don't have an account?
Shahida Robertson
How to Copy Contact Email to Custom Account Field
Hello,
I have created a custom field on the Account object called "Primary Contact Email." I need a trigger that will update this field with the Primary Contact's (lookup on the Account) email. I am not a developer, btw. Right now I have:
trigger UpdateAccountEmails on Contact (after update) {
Map<Id, Account> m = new Map<Id, Account>();
for(Contact c : Trigger.new){
if (Trigger.oldMap.get(c.Id).Email != c.Email) {
m.put(c.AccountId, new Account(Id = c.AccountId, Primary_Contact_Email__c = c.Email));
}
}
update m.values();
Can anyone help me? Thanks!
I have created a custom field on the Account object called "Primary Contact Email." I need a trigger that will update this field with the Primary Contact's (lookup on the Account) email. I am not a developer, btw. Right now I have:
trigger UpdateAccountEmails on Contact (after update) {
Map<Id, Account> m = new Map<Id, Account>();
for(Contact c : Trigger.new){
if (Trigger.oldMap.get(c.Id).Email != c.Email) {
m.put(c.AccountId, new Account(Id = c.AccountId, Primary_Contact_Email__c = c.Email));
}
}
update m.values();
Can anyone help me? Thanks!
I hope the following code helps in learning Apex and Triggers. Let me know if you have any questions on it!
You can use the below code.
I have written a trigger as per your requirement.
<<<<<----Trigger ---->>>>> <<<<<----Apex Class------>>>>>> I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com