You need to sign in to do that
Don't have an account?

Test class for trigger handler class
This is my class please help me out to write test class
public class AccountTriggerHandler implements ITriggerHandler
{
public static Boolean TriggerDisabled = false;
/*
Checks to see if the trigger has been disabled. For example, you could check a custom setting here.
In this example, a static property is used to disable the trigger.
In a unit test, you could use AccountTriggerHandler.TriggerDisabled = true to completely disable the trigger.
*/
public Boolean IsDisabled()
{
return TriggerDisabled;
}
public void BeforeInsert(List<SObject> newItems)
{
// Cast the List<Sobject> to List<Account>
AccountNameCheck((List<Account>)newitems);
}
public void BeforeUpdate(Map<Id, SObject> newItems, Map<Id, SObject> oldItems)
{
// Cast the Map<Id, Sobject> to List<Account>
AccountNameCheck((List<Account>)newitems.values());
}
public void BeforeDelete(Map<Id, SObject> oldItems) {}
public void AfterInsert(Map<Id, SObject> newItems) {}
public void AfterUpdate(Map<Id, SObject> newItems, Map<Id, SObject> oldItems) {}
public void AfterDelete(Map<Id, SObject> oldItems) {}
public void AfterUndelete(Map<Id, SObject> oldItems) {}
/*
Check the accounts to make sure their name does not contain the text "test".
If any do, reject them.
*/
private void AccountNameCheck(List<Account> accountList)
{
// Reject any Accounts which have the word "Test" in the name
for (Account acc : accountList)
{
//if (acc.Name.contains('test'))
//acc.Name.addError('You may not use the word "test" in the account name');
}
}
}
public class AccountTriggerHandler implements ITriggerHandler
{
public static Boolean TriggerDisabled = false;
/*
Checks to see if the trigger has been disabled. For example, you could check a custom setting here.
In this example, a static property is used to disable the trigger.
In a unit test, you could use AccountTriggerHandler.TriggerDisabled = true to completely disable the trigger.
*/
public Boolean IsDisabled()
{
return TriggerDisabled;
}
public void BeforeInsert(List<SObject> newItems)
{
// Cast the List<Sobject> to List<Account>
AccountNameCheck((List<Account>)newitems);
}
public void BeforeUpdate(Map<Id, SObject> newItems, Map<Id, SObject> oldItems)
{
// Cast the Map<Id, Sobject> to List<Account>
AccountNameCheck((List<Account>)newitems.values());
}
public void BeforeDelete(Map<Id, SObject> oldItems) {}
public void AfterInsert(Map<Id, SObject> newItems) {}
public void AfterUpdate(Map<Id, SObject> newItems, Map<Id, SObject> oldItems) {}
public void AfterDelete(Map<Id, SObject> oldItems) {}
public void AfterUndelete(Map<Id, SObject> oldItems) {}
/*
Check the accounts to make sure their name does not contain the text "test".
If any do, reject them.
*/
private void AccountNameCheck(List<Account> accountList)
{
// Reject any Accounts which have the word "Test" in the name
for (Account acc : accountList)
{
//if (acc.Name.contains('test'))
//acc.Name.addError('You may not use the word "test" in the account name');
}
}
}
For Trigger Test class you just need to create the account record only in your test class