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
salesforcesss_deveoper211salesforcesss_deveoper211 

Get profile name in apex trigger

Hi,

 

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.

 

Thaks.

Suresh RaghuramSuresh Raghuram

do like this

 

id id1 = userinfo.getProfileId()
Then
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:     
      $UserProfile.Name

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.