[SalesForce] Get profile name from User without Query

I want to check Profile Name of Users inside a for loop so I need their profile names without querying in apex is there any workaround this.

Best Answer

If you don't want to burn a SOQL Statement and you're working with an SObject, you can use this approach:

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

    $UserProfile.Name

  2. In your trigger, you can refer to the variable;

    for(Object__c obj :triggerNew) { System.debug('Current User Profile: ' + obj.CurrentuserProfile__c); }