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

How to write the Test class for the Apex Trigger
trigger populateContactEmail on Case (before insert , before update){ Set<Id> setConIds = new Set<Id>(); for(Case obj : trigger.new){ if(obj.Secondary_Contact__c != null) setConIds.add(obj.Secondary_Contact__c); } Map<Id , Contact> mapCon = new Map<Id , Contact>([Select Id, Email from Contact where id in: setConIds]); for(Case obj : trigger.new) { if(obj.Secondary_Contact__c != null) { //Protecting against bad Ids if ( mapCon.containsKey(obj.Secondary_Contact__c)) { Contact c = mapCon.get(obj.Secondary_Contact__c); obj.Secondary_Contact_Email__c = c.Email; } } } }
You can use the below Test class code.
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
All Answers
You can use the below Test class code.
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