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
nelrib88nelrib88 

Hel pwith test code for before update trigger

i have a trigger that im trying to create a test for and not sure why the coverage is always 0%.

 

my trigger is

trigger InvalidEmailContactTrigger on Contact (before update)
{
    private String emailissue {get; set;}
    if(Trigger.isBefore)
    {
        emailissue = null;
        for(Contact contact : trigger.old)
        { 
            emailissue = contact.itracmedia__Email_Issue__c;
        }
        
        for(Contact contact : trigger.new)
        {            
            if(contact.itracmedia__Email_Issue__c == null && emailissue != null)
            {             
                EmailIssueRemover.removeEmailIssue(contact.id, emailissue);
            } 
        }
    }
}

 and my test code is

@isTest
private class TestInvalidEmailContactTrigger
{
    public static testmethod void testInvalidEmailContactTrigger()
    {                       
        //Insert a new instance of Contact Object with test values 
        Contact c = new Contact(LastName = 'Test');
        c.itracmedia__Email_Issue__c = 'TestIssue';
        insert c;
        c.itracmedia__Email_Issue__c = null;
        update c;
    }
}

 Can someone help me with getting this test to run successfully.

 

thanks,

NR

Andy BoettcherAndy Boettcher

If it's still 0%, odds are that you have a runtime error tripping you up.  When you run the test - up near the top you'll see "x failures".  Do you see any failures?

nelrib88nelrib88

I do not see any errors or failures and code completion is also 0. im assuming this might have to do with the webservice callout but im not sure how to handle it.

Andy BoettcherAndy Boettcher

Can you post (or put up on pastebin.ca) your debug log coming out of the test?

nelrib88nelrib88

i figured out what was wrong doing the callout was messing it up so i added some logic so that if it is a test it skips the callout.

 

thanks for the trying to help.

Andy BoettcherAndy Boettcher

Sounds good!