Triggers always run, if you want to limit to certain profiles you need to put conditional logic in the trigger that checks if the current user profile is part of the profile set you want the code to run.
There is no direct way to execute trigger for particular profiles. But there is a workaround which you can implement in your code. Workaround is as follows. Create a custom setting, where you will define profiles for which your trigger will execute. Allowed Profile For Trigger custom setting of List type, Store each profile as a record in this custom setting. You can store profile name. Then In your Apex trigger, before doing anything first confirm that current user's profile is present in custom setting or not? If present thengo with your logic.
In trigger
you have to get current user's profile name.
Grab all Profiles from custom setting in a set.
Check if current profile exist in custom setting profiles then write you further logic.
Trigger will fire for all profiles but you can run your particular code as per profile for which you want to run. If user profile exists in the custom setting your code will run otherwise not. You need to put this condition in your trigger code.
Hi Guru,
There is no direct way to execute trigger for particular profiles. But there is a workaround which you can implement in your code.
Workaround is as follows.
Create a custom setting, where you will define profiles for which your trigger will execute.
Allowed Profile For Trigger custom setting of List type, Store each profile as a record in this custom setting. You can store profile name.
Then In your Apex trigger, before doing anything first confirm that current user's profile is present in custom setting or not?
If present thengo with your logic.
In trigger
Thanks
Ashif
Trigger will fire for all profiles but you can run your particular code as per profile for which you want to run. If user profile exists in the custom setting your code will run otherwise not. You need to put this condition in your trigger code.
Regards
Ashif