function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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:, the email domain field should be ','. 

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:,, 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 = '', AccountId = a.Id, MailingCountry = 'US', MailingState = 'CA');
        Contact c2 = new Contact(LastName = 'Stephanie Kry', Email = '', 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(',', a.Email_Domains__c);
        //test delete case
        delete c2;
        a = [SELECT Email_Domains__c FROM Account WHERE Id = :a.Id];
        system.assertEquals('', 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.