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
gidiemgidiem 

Access a trigger name within a running trigger

We are implementing a system to toggle triggers ON and OFF from the UI. A custom seeting is deciding wheter it is ON or OFF but I want the code to be dynamic so I can also streamline the implementation. This also would help down the road if a trigger changes name and the developer forgets to change the hardcoded statement.

I need to access the trigger name within the trigger using metadata - is this possible?
Nithesh NNithesh N

Hi Gidiem, 
Try this Link (https://salesforce.stackexchange.com/questions/65096/how-to-get-the-trigger-name-in-trigger-itself-using-apex),  Here they artificially generated an exception and grabbed that String output which is then processed to get the Trigger Name. 

I hope it answers your query. Please Mark this solution as Best Answer to mark this question as solved.

Best,
Nithesh

Raj VakatiRaj Vakati
Hi ,
You can Query ApexTrigger directly
SELECT Id ,Name from ApexTrigger

 
gidiemgidiem
Hi Nitesh,
Thanks for the tip, I saw that solution previously this morning which seems like a hacky workaround to the problem - raising an exception should be done if there is an exception not to parse a string ang gather information to build dynamic code. Thanks regardless.

Rajamohan - That returns every Id, Name from the existing triggers. I only want the name from the trigger that is currently running at that point in time.