[SalesForce] Report to get all roles in salesforce (with assigned users and without users)

I need a report that shows all roles. Currently I have created a report on user which shows those roles which have users assigned, but I need to show all roles with or without users assigned.

Best Answer

You can't run a report against the UserRole object but you can try this instead:

  1. Go into the Developer Console and select the SOQL query tab or you can login to workbench.developerforce.com.

  2. Go to the Queries Menu/SOQL Query

  3. Paste this query in the query box and click the Execute (or Query) button.

This query selects all roles that are not found in the User table.

SELECT Id, Name
FROM UserRole
WHERE Id NOT IN (SELECT UserRoleId FROM User WHERE UserRoleId !='000000000000000')

This is what you get:

enter image description here

You can then run the same query a bit modified to get all Roles that are assigned

SELECT Id, Name
FROM UserRole
WHERE Id IN (SELECT UserRoleId FROM User WHERE UserRoleId !='000000000000000')

The results can be placed in excel and then imported to a custom object where you can create a report on it if you wanted.

Related Topic