function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Chris Voge 9Chris Voge 9 

Sharing Rules are not enforced when querying ListView object

Hello,
I'm trying to populate a lightning select component with
a list of list views. It's retrieving ALL list views instead of what
the current user has access to.

I would expect the "with sharing" in the class would enforce the
sharing rules. The "getListViews" method is being called from a lightning
controller (JavaScript code). Can someone investigate ? (See Below)

Thanks, Chris


 
public with sharing class LX_Controller {

    @AuraEnabled
    public static  List<ListView>  getListViews( String sObjectType) {
        List <ListView> listviews = (List <ListView>)Database.query('SELECT Id, Name, SobjectType FROM ListView   WHERE SobjectType =\'' + sObjectType + '\'');
        return listviews;
    }
...
}



 
Chris Voge 9Chris Voge 9
We are using Lightning Communities - Partner Central template
Raj VakatiRaj Vakati
ListView is not the same like the salesforce object .. It will be controlled by the Profile Permission like Manager list views and etc ..
 
Change your code as shown below ..
 
Select Id , CreatedById from ListView where CreatedById=:
 
public with sharing class LX_Controller {

    @AuraEnabled
    public static  List<ListView>  getListViews( String sObjectType) {
        List <ListView> listviews = (List <ListView>)Database.query('SELECT Id, Name, SobjectType FROM ListView   WHERE SobjectType =\'' + sObjectType + '\' AND CreatedById='+UserInfo.getCurrentId());
        return listviews;
    }
...
}


 
Chris Voge 9Chris Voge 9
Tried it. Got no records to come back.