You need to sign in to do that
Don't have an account?
Andrew2X
Inconsistent response to 'SELECT Id, Name FROM UserRole'
One of our customers is experiencing an issue where a query to the standard UserRole object is returning no results for some users and correct results for others.
At first I thought this was a permissions issue, but I could find no place in Salesforce where one can set permissions on the UserRole object. Also, one of the users this issue happens to has 'System Administrator' profile (i.e. 'Modify All')
The code is as follows... in Apex, there is a SOQL query to get a list of all roles:
for(UserRole[] roles : [SELECT Id, Name
FROM UserRole
WHERE (PortalType = null OR PortalType = 'None')
ORDER BY Name
LIMIT 1000])
{
}
This works fine all of the time for all users. The results of this query is used to populate a drop-down box to allow the user to select a particular Role.
Later, the selected Role is used in another query:
for (UserRole userRole : [SELECT Id, Name
FROM UserRole
WHERE Id = :roleId])
{
}
Here, the :roleId is the one selected previously by the user. In all cases, it's a valid UserRoleId, but the issue is that for some users this returns a valid Role and for others it returns nothing.
I have not been able to reproduce the error in our Salesforce orgs, and it happens only for one single customer and not for our other customers. I have done a lot of investigating to try to solve this issue but am completely stumped.
I tried using Developer Console to see what the exact query is being sent to Salesforce, but it has been no help because it does not reveal the exact query, but something like this: 'SELECT Id, Name FROM UserRole WHERE Id=:tempVar1
Any help would be greatly appreciated.
Thanks,
Andrew
At first I thought this was a permissions issue, but I could find no place in Salesforce where one can set permissions on the UserRole object. Also, one of the users this issue happens to has 'System Administrator' profile (i.e. 'Modify All')
The code is as follows... in Apex, there is a SOQL query to get a list of all roles:
for(UserRole[] roles : [SELECT Id, Name
FROM UserRole
WHERE (PortalType = null OR PortalType = 'None')
ORDER BY Name
LIMIT 1000])
{
}
This works fine all of the time for all users. The results of this query is used to populate a drop-down box to allow the user to select a particular Role.
Later, the selected Role is used in another query:
for (UserRole userRole : [SELECT Id, Name
FROM UserRole
WHERE Id = :roleId])
{
}
Here, the :roleId is the one selected previously by the user. In all cases, it's a valid UserRoleId, but the issue is that for some users this returns a valid Role and for others it returns nothing.
I have not been able to reproduce the error in our Salesforce orgs, and it happens only for one single customer and not for our other customers. I have done a lot of investigating to try to solve this issue but am completely stumped.
I tried using Developer Console to see what the exact query is being sent to Salesforce, but it has been no help because it does not reveal the exact query, but something like this: 'SELECT Id, Name FROM UserRole WHERE Id=:tempVar1
Any help would be greatly appreciated.
Thanks,
Andrew