• Marie Pardun 3
  • NEWBIE
  • 10 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
My test case for a before insert/update trigger on Contact should be very simple, which means I am missing something obvious...the trigger itself takes the City, State Code, and Zip and pulls the county name from a custom county object.  This trigger is working as intended and populates the county name with no issue.  

What I can't figure out is why my test class does not return a value for the county after the insert.  (The insert code and requery works perfectly when running in an Execute Anonymous window). 

Below is the code for the insert test.  After inserting a new contact, when I try to requery for the new hed__Mailing_County__c value, the value is null, but it does pull the new contact id.  Any help is much appreciated!  :-)
 
@isTest
private class Contact_County_Test {
    static testMethod void TestInsertContact() {
        // Create contact with city, state, zip populated
        Contact con = new Contact(FirstName = 'TestInsert', 
                                  LastName = 'TestContact', 
                                  MailingCity = 'My City', 
                                  MailingStateCode = 'WI', 
                                  MailingPostalCode = '12345',
                                  MailingCountryCode = 'US',
                                  hed__Mailing_County__c = '');
        Insert con;

        //Requery to pull in new county name
        con = [SELECT hed__Mailing_County__c FROM Contact WHERE Id = :con.Id LIMIT 1];

         //Verify County Name is populated correctly
         System.assertEquals('County Name', con.hed__Mailing_County__c);
    }
}

 
My test case for a before insert/update trigger on Contact should be very simple, which means I am missing something obvious...the trigger itself takes the City, State Code, and Zip and pulls the county name from a custom county object.  This trigger is working as intended and populates the county name with no issue.  

What I can't figure out is why my test class does not return a value for the county after the insert.  (The insert code and requery works perfectly when running in an Execute Anonymous window). 

Below is the code for the insert test.  After inserting a new contact, when I try to requery for the new hed__Mailing_County__c value, the value is null, but it does pull the new contact id.  Any help is much appreciated!  :-)
 
@isTest
private class Contact_County_Test {
    static testMethod void TestInsertContact() {
        // Create contact with city, state, zip populated
        Contact con = new Contact(FirstName = 'TestInsert', 
                                  LastName = 'TestContact', 
                                  MailingCity = 'My City', 
                                  MailingStateCode = 'WI', 
                                  MailingPostalCode = '12345',
                                  MailingCountryCode = 'US',
                                  hed__Mailing_County__c = '');
        Insert con;

        //Requery to pull in new county name
        con = [SELECT hed__Mailing_County__c FROM Contact WHERE Id = :con.Id LIMIT 1];

         //Verify County Name is populated correctly
         System.assertEquals('County Name', con.hed__Mailing_County__c);
    }
}