You need to sign in to do that
Don't have an account?
Mark Z Dean
Querying UserRole Object
I ran simple query below and it gave me results:
select Id, name, userrole.name from userThe child relationship name is called 'Users' on the User object so I was initially the query below but it kept erroring out:
select Id, name, users__r.name from userI thought every call to a parent must have '__r' appended but not in this case plus it doesn't even use the relationship name i.e. users. Can someone explain why the first query worked and the second one didn't...Many thanks...
While in your second Query "Users" is Child and "User" is parent. So the reason why your query is failing because you are running a query on "Parent (User)" and refercncing "Child (Users)" fields which will eventually fail as the system is not able to determine which child to refer to as technically there can be multiple of them. If you want to try, go ahead and query on "Users (child)" and try referncing "User (parent)" object, it will work.
Hope this helps you!
be called as below? I thought every relationshop call should have a '__r' appended to it?
Below Query can fulfill your requirements, Hope this will work for you.
1. [Select Id,Name,UserRole.Name from user]
Even you can use below one to see username and role on the same row
2. [Select Id,Name,UserName,UserRole.Name from user]
Please mark this as best answer if this solves your problem.
Thank you,
Ajay Dubedi
I am little late to the party but the reason is a custom relationship has '__r' suffixed but standard does not.
For example, take the relationship you were exploring with UserRole. Similarly, if you were to access fields of Profile object from within the User query, you can do so by simply using "Profile.Id" or "Profile.Name".
Same principal applies when you want to access a field of Account object from Contact.
e.g. However, when it comes to custom relationships, '__r' is used for querying relationship.
e.g.
Hope this helps.