• mahika agrawal
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hi, I wrote a trigger and a test class, but when testing I get below error: 

System.DmlException: Update failed. First exception on row 0 with id 003M000000Zc1NaIAJ; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, PopulateContactAreaCode: execution of BeforeUpdate
caused by: System.NullPointerException: Attempt to de-reference a null object
Trigger.PopulateContactAreaCode: line 5, column 1: []

Trigger:
trigger PopulateContactAreaCode on Contact (before insert, before update) {

    for(Contact contact : Trigger.new)
    {
        string AreaCode = CountryRegion__c.getInstance(contact.MailingCountry).Area_Code__c;
        contact.Area_Code__c = AreaCode;
    }
}

test class:
@isTest
public class PopulateContactAreaCodeTest
{
    static testMethod void attTriggerTest1()
    {
        test.startTest();
        Account acct = new Account(id = '001M000000iLhTL', Name = 'Test Account ', Mailing_Country__c = 'Afghanistan');
        update acct;      
        Contact con = new Contact(id = '003M000000Zc1Na', LastName = 'Test Contact', Account = acct, Email = 'test@test.com', Mailing_Country__c = 'Afghanistan', MailingCountry = 'Afghanistan');
        update con;
        delete con;
        test.stopTest();
    }
}

any idea what I added wrong?

thank you in advance
  • February 24, 2015
  • Like
  • 2