+ Start a Discussion
vamsi varmavamsi varma 

Criteria Based sharing rules using apex

Hi i have to give sharing rules to different users and groups for an object.

I want give them using apex managed sharing rules.



i have used this links as reference and i have listened that using apex we shouldnt write sharing rules.

is this right way to write criteria based sharing rules using apex, anyone please let me know.

Thanks in Advance,
Vamsi Varma.

Navee RahulNavee Rahul
Hello Vamsl,

As for i know, if you have applied sharing rule on Object. for user and groups.
it will work perfect in Standard functionality list view,edit,view.

if you need to achive the same using apex class, then you need to use with sharing keyword in class.

if you did not specify the with sharing keyword , then sharing rule will not be applied for the VF page you created.


Standard Object list view will apply standard sharing rule.

Custom VF page with Custom codes to list data will not apply sharing rule unless specified in the code.

mark if this answer helps you.

D Naveen rahul.

Criteria based sharing rules are not created via Apex.

You can write apex to give the access of user via code which is called Apex Managed Sharing.

Ashlekh Gera