You need to sign in to do that
Don't have an account?
Help with Apex test method for contacts
I have a trigger that i need a test class for but I am limited in my apex test writting. Can someone help me with a test method for the fllowing code below? I would really appreciate it.
trigger Trigger_ContactBouncedEmailBeforeUpdate on Contact (before update)
{
//Assign the context before and after the change into a Map
Map<Id,Contact> newContactMap = Trigger.newMap;
Map<Id,Contact> oldContactMap = Trigger.oldMap;
//Loop through the map
for(Id contactId:newContactMap.keySet()){
Contact myNewContact = newContactMap.get(contactId);
Contact myOldContact = oldContactMap.get(contactId);
if (myNewContact.EmailBouncedReason <> myOldContact.EmailBouncedReason){
//if Salesforce is modifying these fields we want to reset are
myNewContact.IsEmailBounced__c = false;
myNewContact.EmailBouncedReason__c = null;
myNewContact.EmailBouncedDate__c = null;
}
if (myNewContact.IsEmailBounced__c <> myOldContact.IsEmailBounced__c){
if(myNewContact.IsEmailBounced__c == true)
{
myNewContact.EmailBouncedDate = myNewContact.EmailBouncedDate__c;
myNewContact.EmailBouncedReason = myNewContact.EmailBouncedReason__c ;
}
if(myNewContact.IsEmailBounced__c == false)
{
myNewContact.EmailBouncedDate = null;
myNewContact.EmailBouncedReason = null;
myNewContact.EmailBouncedReason__c = null;
myNewContact.EmailBouncedDate__c = null;
}
}
}
}
try this.