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
MattreyMattrey 

Determine trigger status in test method

Is there a way to determine the status of a trigger (active/inactive) in a test method?

I have tests that have assert() calls in them that assume the trigger is active. If I need to deactivate the trigger, I then need to go and change the test so that it still passes. It would be nice to be able to do something like:

if (trigger.status='Active'){

  System.assert(trigger was fired);

}

Best Answer chosen by Admin (Salesforce Developers) 
Pradeep_NavatarPradeep_Navatar

you can use below SOQL query on apextrigger object :

 

ApexTrigger aa = [Select id,a.Status From ApexTrigger a where Status ='Active'];

 

Did this answer your question? if so, please mark it solved.

All Answers

Pradeep_NavatarPradeep_Navatar

you can use below SOQL query on apextrigger object :

 

ApexTrigger aa = [Select id,a.Status From ApexTrigger a where Status ='Active'];

 

Did this answer your question? if so, please mark it solved.

This was selected as the best answer
MattreyMattrey

Nice - so I should be able to dosomething like

 

ApexTrigger trigger = [SELECT Status from ApexTrigger WHERE Name='myTestTrigger'];

if (trigger.Status='Active){

//do assert

}

 

Thanks Pradeep!