[SalesForce] How to get the profile name and role name from User object

We already have a soql query to retrieve the User object (which returns the role id and profile id) was wondering if we could retrieve the RoleName and ProfileName from within the same query instead of making an additional query to userInfo object.It will be of great help if you could please point us in the right direction

Note : Also we want to retrieve this for a seq of users so it would save a lot of additional calls if we could retrieve those details in the same call for User object

Best Answer

You can just use:

select id, name, <my other fields>, 
       profile.name, userrole.name 
from user 
<optional where condition>

For details on how this works, you can refer to the Name object's documentation.