Is there any table or any other way(metadata/rest api) we can query the list views of a particular object that a user/group has access.


SELECT Name FROM table_x
WHERE UserOrGroupId = '1234..'
AND  SobjectType = 'Account'

I can see an object named UserListView in workbench, but query on that returns no data. Is it deprecated?

  • 2
    From my experience you can export object w metadata API and that includes list view component. That will list what the sharing is on the list view, but then you need to figure out if the user is in group or role or if group shares w hierarchy then of user is in hierarchy, etc. If there is an easier way would love to know, but listviews are pretty hard to get at from what little I know. Looked at setupentityaccess per the post but looks like just apex class, VF page, connected apps, custom permission, and one other thing I forget, but not list views
    – gorav
    May 2 '16 at 23:40
  • Yes @gorav, can you please tell me the code to get the ListView metadata and then check who all has access to this list view. I am new to Metadata Api and the requirement is kind of urgent. May 3 '16 at 3:20
  • I can only say it's quite complicated, as far as I know. Using workbench you can extract the metadata for any object and it will include the list views. From there it's going to take a lot of work to parse the XML and then figure out how to get at who else has access via shared to. I do not have an answer, can just point you in the direction.
    – gorav
    May 5 '16 at 23:59

Permissions to access an object are generally a matter of both a user's profile and any permission sets that have been assigned to them. In this particular case, since you're talking about a list view, you're going to want to first take into consideration access to records of the parent object since the list view would be considered a child of that object. Without access to records that are included in that list view, a user won't have access to it.

I believe the data that you're looking for is hidden in the SetupEntityAccess. You'll see a visual model of the ERD here.

I think your query should look something like:

SetupEntityAccess[] accessSettings = [SELECT Id FROM SetupEntityAccess WHERE
    SetupEntityId IN (SELECT Id FROM ListView WHERE NamespacePrefix = :your_namespace 
    AND Name = :Your_List_View) AND ParentId IN (SELECT PermissionSetId 
    FROM PermissionSetAssignment WHERE AssigneeId = :UserInfo.getUserId()) LIMIT 1];

Note: that you may need to run a separate query restructured around ObjectPermissions depending on how you're granting access to the records.

You may want to see @eyescream answer to this related post: How do I find out if a user has access to a visualforce page through apex?.


I did some further research, including using Workbench to check the metadata on SetupEntityAccess. I discovered that SetupEntityAccess is not the object to be running your query on, and that ListView is not one of its children. Going beyond that, I don't even think that ListView is what you want to be looking at as your starting point!

Instead, I believe the object that you're looking for is UserListView! One of its children is UserListViewCriterion. Some of its fields include Id, sObjectType (all standard objects + custom objects), ListViewCharts and UserId. I believe this is what you're looking for and that you can run a direct query on it since it is queryable.

The UserListView is a child of ListView, so you should be able to relate UserListView back to the ListView for each object that you're interested in. While there is no CustomObject to query on, that's what the metadata API showed the ListView being a child of. That suggests to me that each ListView is a child of each sObjectType that it's created for. I've not constructed a query, but I'd suggest an approach that either uses UserListView in a subquery for ListView or vice-versa since the two are closely related while at least specifying the sObject and perhaps a list of UserIds to select from.

I hope this points you in the right direction to find the results that you're looking for.

  • Thanks @crmprogdev. But when I run this for ListView, it is not showing any result where as for ApexClass or VF page this query is showing result. Is it working for you? Do I need to enable some permission for ListView? May 3 '16 at 3:17
  • See my edited answer
    – crmprogdev
    May 3 '16 at 13:45
  • when I query UserListView object I see no records. Do you know why it is like this? May 10 '16 at 10:31
  • As I said in my answer, I'm not entirely certain how you'll need to make your query, only that the UserListView is a child of ListView. I strongly suspect you'll need to make a query that involves both where one is a subquery and you may need to include UserIds or perhaps filters. It's something you'll need to play with in order to get results.
    – crmprogdev
    May 10 '16 at 12:56

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.