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

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.

  • 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 ? – user2359997 Sep 14 '18 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 Sep 14 '18 at 21:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.