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

How to get profile name without query
Is there any way to get the profile name of logged in user without querying the user object.
I know the following solution:
String usrProfileName = [select u.Profile.Name from User u where u.id = :Userinfo.getUserId()].Profile.Name;
Instead of this I want to save 1 query so if there is any method to get the profile name in apex without firing the query please let me know.
Thanks,
I'm don't think there is - I've never come across one. (You can get the profileId from the UserInfo by the way - UserInfo.getProfileId() which tidies your code up a bit).
Why do you want to save 1 query? Is there somewhere else you could get this saving?
As a suggestion, you can sometimes get away with getting related information in another query. For example, if you were doing an account listing, you might do something like this:
List<account> useraccounts = [select id,name,owner.profile.name from account where ownerid = :userinfo.getuserid()];
This would give you the account information you were looking for, while also grabbing the user's profile name. Given that there is no apparent way to get the name without a query, if you can leverage another query to get the data, you can save yourself an SOQL call.
If you're bumping up against the upper limits of the governor, restructuring or combining queries might be a solution. I had a project like that where I was ultimately hitting over 30 queries per trigger, and I reduced it to 14 by restructuring the code to take advantage of similar queries.
However, that being said, if you're only at 3 or 4 queries, don't optimize unless you see a major performance hit. Saving one query, especially one that's only one row, isn't the best use of your time. Focus on larger queries where you could get better performance, and if you still need that extra query, then work in a solution to grab that information while you're working on related data.
I'm trying to do something similar. I'm trying to write an Apex trigger that fires each time an Account is updated. Whenever the Owner changes, I want another field to be updated based on the new Owner's profile. But I need to do this without running any SOQL queries because otherwise, Salesforce won't let me do a mass transfer of Account ownerships. I can't do a formula because for whatever reason, it won't let me access the Account Owner from there. I can write a bunch of workflows, but I have to write one for each user in the system. There must be a more elegant way of doing this.
Any ideas out there?
I tried something like this:
Trigger.new[i].Owner.Profile.Name.compareTo("Sales User"), where Trigger.new[i] is the Account after it has been updated. But I keep getting these NULL reference exceptions. So is there a way for me to access the Account Owner's Profile Name from the trigger without running a SOQL query?
Andrew, did you ever figure this out? I'm working on the same thing.
Andrew did you figure this out?I am also looking for a solution for this.
Hi.
To display Profile Name in VF page you can do like this.
{!$Profile.Name}
cheers
suresh
You can use following method to by pass for any specific user by saving his/her User name in the Label and add check as follows :
!UserInfo.getName().contains(Label.Client_User))
Else
Check the following link to get it through script :
http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_getuserinfo.htm
Hope this helps,
Thanks,
Prashanth
Best answer to your query is using the following syntax :
{!$profile.name}
So, the only way to get the profile name in Apex is by querying the User object as you have shown in your code.
itunes (https://myappforpc.com/app/915061235/itunes-store)
This field can be used in query.