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
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


 
Tuan Ho 8Tuan Ho 8
For any people who make the same mistake like me: Make sure you "Save All" before you "Run All". This is not Visual Studio, files are not automatically saved before running :)))
Heena KausarHeena Kausar
My code wa exactly same as suggested above, but did not work even after trying multiple times. What finally worked is performing Test->RunAll option in Developer Console before submitting the challenge to trailhead.
Mehaboob BashaMehaboob Basha
I created a new playground and added same code again, it worked