1

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

1 Answer 1

2

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.

3
  • Thanks a lot for your response! Please excuse my ignorance as i'm fairly new to salesforce as per my understanding profile and userRole are two different objects can we query those object when querying user object ? Commented Sep 14, 2018 at 20:35
  • Not a problem, we all learn Salesforce everyday. Yes, those are different objects, but are "related to" user. In general, if you have a relationship between two objects, you can lookup fields from the other in a single query.
    – Jayant Das
    Commented Sep 14, 2018 at 21:45
  • @JayantDas worth nothing the current user cannot access the information (even on their own record) without the View All data permission Commented Aug 14, 2020 at 18:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .