• TCD
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies

I'm about to pull my hair out, so would really appreciate it if someone could help me see the simple mistake I must be making here.  I have a trigger that works perfectly when I perform manually the same steps I have written into the unit test.  I thought maybe it was that my trigger is a before update trigger, so I added some extraneous updates after the update in this test, but that didn't help.  And, when I do the updates manually exactly as in this unit test, it works, without extraneous follow-on updates.

 

Here's the trigger:

 

 

trigger searchZipCode on Account (before update) {

    // For each Account in the Trigger.new list of Accounts
    for (Account a : Trigger.new) {
        // check if the BillingPostalCode field is contained in the list of zips
        try {
            if (a.BillingPostalCode != NULL){
                if (a.ZipSearchList__c.contains(a.BillingPostalCode.substring(0,5)))
                {
                    a.ZipFound__c = TRUE;
                } else a.ZipFound__c = FALSE;
            }
        } catch (System.NullPointerException e) {
            system.debug(e.getMessage());
            a.ZipFound__c = FALSE;        
        } finally {
            // do nothing     
        }           
 }
}

 

 

 

Here's the unit test:

 

 

@isTest
private class searchZipCodeTest {

    static testMethod void testsearchZipCode() {
        String ziplist = '12345, 67890';
        String successZip = '12345';
        String failZip = '66666';
        
        Account successAccount = new Account(
            Name = 'Success University',
            // RecordType = '012A00000004OUY',
            Type = 'Graduate Institution',
            BillingPostalCode = successZip,
            ZipFound__c = FALSE
        );
        
        Account failAccount = new Account(
            Name= 'Fail University',
            // RecordType = '012A00000004OUY',
            Type = 'Graduate Institution',
            BillingPostalCode = failZip,
            ZipFound__c = FALSE
         );
        insert new Account[] { successAccount, failAccount };
 
        successAccount.ZipSearchList__c = ziplist;
        failAccount.ZipSearchList__c = ziplist;
        update successAccount;
        update failAccount;
        
        Test.StartTest();
        System.assertEquals('12345', successAccount.BillingPostalCode);
        System.assertEquals('12345, 67890', successAccount.ZipSearchList__c);
// This is the assert that fails:
System.assertEquals(TRUE, successAccount.ZipFound__c); System.assertEquals(FALSE, failAccount.ZipFound__c); Test.StopTest(); } }

 

 

 

Here's the error message: