1

I have a RemoteAction in my code that queries data. I receive all the records irrespective of the fact that with sharing has been used for the containing class.

Does RemoteAction NOT respect sharing settings?

I read the documentations here and here. and my Controller version is 36.0. but still not pretty sure.

2
  • Are you sure ?With sharing should respect sharing settings ?Check for profile of the user to see he does not have view ALl or modify all access ? Commented May 18, 2016 at 16:06
  • Yes @MohithShrivastava...on adding the solution by Adrian it seems to work. But not sure why it returns all the records without it. Have raised a ticket with Salesforce...
    – ipradhansk
    Commented May 18, 2016 at 16:51

1 Answer 1

2

I was only able to reproduce the behavior you describe by changing the controller to without sharing. Regardless, this workaround should let you filter out records which should not be viewable:

@RemoteAction
public static List<MyObject__c> getRecords()
{
    Map<Id, MyObject__c> records = new Map<Id, MyObject__c>([
        SELECT Name FROM MyObject__c
    ]);

    List<MyObject__c> viewable = new List<MyObject__c>();
    for (UserRecordAccess access : [
        SELECT RecordId FROM UserRecordAccess
        WHERE UserId = :UserInfo.getUserId()
        AND HasReadAccess = true
        AND RecordId IN :records.keySet()
    ]) viewable.add(records.get(access.RecordId));
    return viewable;
}
1
  • The fix works. Not sure about the issue with sharing in RemoteAction...Thanks :)
    – ipradhansk
    Commented May 18, 2016 at 16:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .