function readOnly(count){ }
Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
trigger CopyAccountEmailToContactEmail on Account (after update) { Map<Id, String> m = new Map<Id, String>(); for (Account a : Trigger.new) { Account old = Trigger.oldMap.get(a.Id); if (a.Email__c != old.Email__c) { m.put(a.Id, a.Email__c); } } if (m.size() > 0) { Contact[] contacts = [ select Id, AccountId from Contact where AccountId in :m.keySet() ]; for (Contact c : contacts) { c.Email = m.get(c.AccountId); } update contacts; } }
@istest public class EmailCopyTest { static testMethod void myTest() { Account acc= new Account(); acc.name='sample'; acc.Email__c='sample@gmail.com'; insert acc; Contact con= new Contact(); con.lastname='sample'; con.AccountId=acc.id; insert con; acc.Email__c='sample123@gmail.com'; update acc; system.assertEquals('sample123@gmail.com', acc.Email__c) ; } }
Can you try the below apex trigger and test class.
Trigger:
Test Class:
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks
All Answers
Can you try the below apex trigger and test class.
Trigger:
Test Class:
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks
Sai Praveen for your respond.!!