+ Start a Discussion
m@x~W0W~m@x~W0W~ 

Somebody plz help me out with the test class for the following trigger.

trigger teachHindi on Contact (before insert, before update) 
{
//////////////////////////////////////
// Do not allow any teacher to insert/update if that teacher is teaching Hindi.
// Created 20131009 max
// Modified 20131009
//////////////////////////////////////
    if(Trigger.isBefore && Trigger.isInsert)
    {
        for (Contact cont : Trigger.new)
        {            
            if(cont.Subject__c == null)
            {
                cont.addError('Subject Field Cannot be left blank');
            }
            
            else if(cont.Subject__c.Contains('Hindi'))
            {
                cont.addError('can\'t insert as hindi is taught');
            }
        }
    }
    else if (Trigger.isBefore && Trigger.isUpdate)
    {
        for (Contact cont : Trigger.new)
        {
           if(cont.Subject__c == null)
            {
                cont.addError('Subject Field Cannot be left blank');
            }
            
            else if(cont.Subject__c.Contains('Hindi'))
            {
                cont.addError('can\'t insert as hindi is taught');
            }
        } 
    }
}

 

Abhi_TripathiAbhi_Tripathi

Hey max,

 

Why that else condition in your trigger as both looks same

 

and for test class you can check out this blog

http://abhithetechknight.blogspot.in/2013/10/salesforce-test-class-basics.html