You need to sign in to do that
Don't have an account?

Get Profile Name in Trigger.
I need to get current user profile name in trigger. I tried by using following way. Is there any possibility to get profile name directly without query.
trigger triggerName on CustomObject(after Insert){
Profile ProfileName = [select Name from profile where id = :userinfo.getProfileId()];
if(ProfileName.Name=='System Administrator'){
//code
}
}
Unfortunately not, the UserInfo class gives you the details of the logged in user and that only has the id of the profile.
All Answers
Unfortunately not, the UserInfo class gives you the details of the logged in user and that only has the id of the profile.
Is there any other option like system.profileName or session.ProfileName?
Unforunately not. The UserInfo would be the holder for that type of information.
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;
Hope this helps.... You can do the same for the Role name too.
Called that UserProfile__C in the trigger
trigger NoDeleteOpportunity on Opportunity (Before Delete) {
for (Opportunity q: trigger.old)
{ if (q.NoDelete__c == true)
{
If (q.UserProfile__c == 'Sales Rep'){
q.adderror('Closed Opportunity can not be Updated. Please contact System Admin');
}
}
}
}