+ Start a Discussion

System.AssertsEquals doesn't match System.Debug result


I'm getting a failure in my test class. Below is my sample. The piece of code that is being tested updates an Account's Email Domain field with the email domains tied to related Campaigns. For example, if we have an Account X and two Contacts related to Account X with email addresses: cmlam@cmlam.com skry@sky.com, the email domain field should be 'cmlam.com,sky.com'. 

In my test class below, the System.Debug comes back with the correct email domains related to the Account but the test class is apparently failing because in the 'System.AssertsEquals' portion, the actual result is Null. Here is the error message: 
System.AssertException: Assertion Failed: Expected: cmlam.com,sky.com, Actual: null
Stack Trace: Class.ContactTrigger_tests.updateAccountEmailDomains_test: line 34, column 1

Any ideas? 
public static testmethod void updateAccountEmailDomains_test(){
        //initialize data
        Account a = new Account(Name = 'Anthem', BillingCountry = 'US', BillingState = 'CA');
        insert a;
        Account a2 = new Account(Name = 'Synergy', BillingCountry = 'US', BillingState = 'CA');
        insert a2;        
        Contact c = new Contact(LastName = 'CM Lam', Email = 'cmlam@cmlam.com', AccountId = a.Id, MailingCountry = 'US', MailingState = 'CA');
        Contact c2 = new Contact(LastName = 'Stephanie Kry', Email = 'skry@sky.com', AccountId = a.Id, MailingCountry = 'US', MailingState = 'CA');        
        List<Contact> contactList = new List<Contact>();
        insert contactList;
        a = [SELECT Email_Domains__c FROM Account WHERE Id = :a.Id];
        system.assertEquals('cmlam.com,sky.com', a.Email_Domains__c);
        //test delete case
        delete c2;
        a = [SELECT Email_Domains__c FROM Account WHERE Id = :a.Id];
        system.assertEquals('cmlam.com', a.Email_Domains__c);

AbhishekAbhishek (Salesforce Developers) 

Can you check the above article, It might answer your query.
Thanks @Abhishek. I already queried Account 'a' in the lines before the System.AssertEquals. Any other ideas? I tried querying for c and c2 as well and I'm getting the same error message.