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
amilawamilaw 

Avoid Sharing to users who have no access to the object

His all,

 

Is there a way to avoid sharing records fro users who dont have access to the object.

 

in soql even we used with sharing keyword, records are retrieved for the users who have sharing records but not read access in profile

AneeshaAneesha

I would suggest you to check OWD for that object. If its public then the soql will return records.

Ashish_SFDCAshish_SFDC

Hi Amilaw, 

 

How are the users doing the search ?

 

Regards,

Ashish

amilawamilaw

OWD is not public

amilawamilaw

code is something like this

 

public with sharing class TestPageController {

public List<Business_Unit__c> bus{get;set;}
public List<String>busString{get;set;}
public TestPageController()
{
bus = [SELECT Name FROM Business_Unit__c];
busString = new List<String>();
for(Business_Unit__c bu : bus)
{
busString .add(bu.Name);
}
}
}

 

<apex:page controller="TestPageController">
<apex:repeat value="{!bus}" var="bu">
{!bu.Name}#####################<br/>
</apex:repeat>

<apex:repeat value="{!busString}" var="bustring">
{!bustring}********************<br/>
</apex:repeat>
</apex:page>

 

 

result is something like this

 

#####################

#####################

#####################

#####################

 

BU1********************

BU2********************

BU3********************

BU4********************

Ashish_SFDCAshish_SFDC

Hi Amilaw, 

 

Did you also verify if there are any Sharing Rules that override the default sharing. 

 

Regards,

Ashish