I need to get a list of users whose role has the first 5 char as ‘Sales’
I want to use this on a apex class
My first thought was to use something like this
select id from user where UserRoleId__r like 'Sales%'
But this throws an error
No such column 'UserRoleId__r' on entity 'User'.
Do i need to query the role object to get all ids and then query the user object using those ids?
is there a better way of doing this?
Thanks
You need to fix the name of the User Role column in your search. Here’s is the correct syntax:
select id from user where userrole.name like 'Sales%'You only need to append the
__rsuffix to relationships in queries when the object is custom. For built in objects, you only need the name of the object (no__r).