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

Get profile name in apex trigger



Can we get $Profile.Name = "System Administrator" in apex trigger.


If no then how can I check if the current user is system admin or not.



Suresh RaghuramSuresh Raghuram

do like this


id id1 = userinfo.getProfileId()
select Name from profile where id = :id1;


Mark it as solution if it answered your question

kevin Carotherskevin Carothers
I know I'm coming late to this party, but I solved this for my particular case by doing the following;

1.  define a formula field (named, say, "CurrentUserProfile) on an object  that has this code:     

2.   In your trigger, you can just refer to the variable;
for(Task t :triggerNew) {
         // ...
         System.debug('Current User Profile: ' + t.CurrentuserProfile__c);
         // ...

Hope this helps.... You can do the same for the Role name too.