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
Pere MartíPere Martí 

Apex Managed Sharing Rules restrictions

Hi guys,

I have a code that is creating some Apex Managed Sharing rules, the problem is that this code is executed by the users that don’t have the permission “Modify all data”, and then the sharing rules are not created.

Is there anyway that a User that has a profile without the permission “Modify all data” can create/edit Apex Managed Sharing Rules?
Because this permission is too wide to freely give it to users, so I was wondering if there is any other permission that you can give, a bit more restrictive, but that will allow the users to create sharing rules.

If the previous option is not possible, is there a way to make a piece of code to be executed by another user, like the System.runAs() that you can use in the testmethods?

Thanks a lot!

ImposterImposter

Hi Pere,

Have you tried using the "without sharing" keyword in your class ?

Pere MartíPere Martí

I looked into the documentation details of your suggestion and as I read I was afraid that it wouldn't solve my problem. But then I found this information hidden in a comment of an example:

 

public without sharing class CWithout {
  // All code in this class ignores sharing rules and operates  
    
  // as if the context user has the Modify All Data permission.

 

This was exactly what I was looking for! I tried it and it seems to be working just fine. :D

 

Thanks a million!! you really saved my life here!!

 

The apex article: http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_keywords_sharing.htm