Wednesday, December 11, 2013

Test Class for Before Trigger in Salesforce

Test Class:

    In the previous post I have posted one Before Trigger .For that Trigger the test class is given Below.

Test Class Code:

  @IsTest
private class Account_Trigger_Test 
{
	private static testMethod void testDelete()
	{
           Account acc=new Account(Name='Test Account;);
           insert acc;
 
           // should succeed
           delete acc;
        }

	private static testMethod void testDeleteFail()
	{
           Account acc=new Account(Name='Test Account',
                                   Client_ID__c='Should fail');
           insert acc;
 
           try
           {
              delete acc;
              // should throw an exception - the following assertion will cause an error if the code carries on
              System.assert(false);
           }
           catch (DMLException e)
           {
               // expected - could assert the message here
           }
        }
}

No comments:

Post a Comment