+ Start a Discussion
Daniel BallingerDaniel Ballinger 

The Trigger 'AccountTrigger' does not appear to be calling the AccountTriggerHandler class correctly or using isBefore or isInsert content variables.

I'm working through Apex & .NET Basics - Understanding Execution Context

When validating the challenge I'm getting the error:
 
Challenge Not yet complete... here's what's wrong: 
The Trigger 'AccountTrigger' does not appear to be calling the AccountTriggerHandler class correctly or using isBefore or isInsert content variables.

The trigger I currently have is minimal:

trigger AccountTrigger on Account (before insert) {
    AccountTriggerHandler.CreateAccounts(Trigger.new);
}

Why would I need to check Trigger.isBefore and Trigger.isInsert if the trigger is only on before insert?

 
Best Answer chosen by Daniel Ballinger
Amit Chaudhary 8Amit Chaudhary 8
Your code should be like below
trigger AccountTrigger on Account (before insert) 
{
	if ( Trigger.isBefore ) 
	{
		if(Trigger.isInsert)
		{
			AccountTriggerHandler.CreateAccounts(Trigger.new);
		}	
	}	
}
I agree with you this trigger is only on before insert so no need of isBefore and IsInsert variable.

This is the trigger framework so multiple even we can use in same trigger that is why we need to use context varaible.

Well you can submit your feedback on same.

User-added image

 

All Answers

Daniel BallingerDaniel Ballinger
Also, calling the "content variables" rather than Trigger Context Variables (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_context_variables.htm) is a bit confusing.
Raja IslamRaja Islam
try this
if (Trigger.isBefore && Trigger.isInsert) 
    AccountTriggerHandler.CreateAccounts(Trigger.New);
Amit Chaudhary 8Amit Chaudhary 8
Your code should be like below
trigger AccountTrigger on Account (before insert) 
{
	if ( Trigger.isBefore ) 
	{
		if(Trigger.isInsert)
		{
			AccountTriggerHandler.CreateAccounts(Trigger.new);
		}	
	}	
}
I agree with you this trigger is only on before insert so no need of isBefore and IsInsert variable.

This is the trigger framework so multiple even we can use in same trigger that is why we need to use context varaible.

Well you can submit your feedback on same.

User-added image

 
This was selected as the best answer
Christopher_Alun_LewisChristopher_Alun_Lewis
I'm Glad I'm not the only one who came accross this. I had the exact same trigger written up, and was very confused by the message. I don't think that these should be part of the testing scope for the challenge. However, if for whatever reason it is seen as necessary, then the inclusion of these context variables should be mentioned in the bullet points associated with the challenge to make it clear.
Amit Chaudhary 8Amit Chaudhary 8
Hi

Please check below post for solution.
1) https://developer.salesforce.com/forums/?id=906F0000000DBRhIAO
2) https://developer.salesforce.com/forums/ForumsMain?id=906F0000000DCwCIAW

Please update your AccountTrigger and add "Trigger.isBefore". AccountTrigger - Trigger On Account Object
 
trigger AccountTrigger on Account (before insert) 
{
    if (Trigger.isBefore && Trigger.isInsert) {
			AccountTriggerHandler.CreateAccounts(Trigger.new);
		}	
	}
Let us know if this will help you