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
TheCustomCloudTheCustomCloud 

VERY Simple SOQL but wont work. Please help.

 

How do I create a string and run this simple soql query that populates it. 

 

 

Example 

String uRoleName = [Select u.Name From UserRole u Where u.id = : UserInfo.getUserRoleId() Limit 1]; 

 

Above doesnt work because it wants an SObject but UserRole is not an accessible sObject and I dont want an instance of it anyways I just want the one field returned into a string. 

Best Answer chosen by Admin (Salesforce Developers) 
J&A-DevJ&A-Dev

String uRoleName = [Select Name From UserRole Where Id = : UserInfo.getUserRoleId() Limit 1].Name;

 

All Answers

J&A-DevJ&A-Dev

String uRoleName = [Select Name From UserRole Where Id = : UserInfo.getUserRoleId() Limit 1].Name;

 

This was selected as the best answer
JimRaeJimRae

You could also do it from a user query if you needed to:

 

 

String uRoleName = [Select UserRole.Name From User Where id = : UserInfo.getUserRoleId() Limit 1].UserRole.Name;