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
v jv j 

how to write apex class to create user sharing rule ?

Needed info on creating User Sharing Rule .In my code trigger written after insert on custom objects record which creates public group and shares that record in that group. Now i wanted to write a User sharing rule for same public group. I am not able to do that.
 
PratikPratik (Salesforce Developers) 
Hi V J,

Here is the sample code to get started:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_bulk_sharing_creating_with_apex.htm

Thanks,
Pratik
v jv j
Hi Pratik,
I have gone through above link, i am looking for different thing not the record sharing. I want to create the " User  Sharing Rule " under Setup/Admin/Security Control/Sharing settings   .
PratikPratik (Salesforce Developers) 
Hi V J,

Is it that you are not able to locate the Public user group in your sharing rule? Have you checked if that public user group is there in the Public Groups list as to verify if the group got created in the system.

Thanks,
Pratik
v jv j
got the pointer to solve the problem, Actually I was using Usershare object insted of usermembershipsharingrule object. 
But problem is yet not solved when i use usermembershipsharingrule object i get compile error "Error: Compile Error: No access to entity: UserMembershipSharingRule at line 1 column 8"

error is due to line  
Usermembershipsharingrule  obj  = new Usermembershipsharingrule();  

Is anybody have idea why is this error ?
PratikPratik (Salesforce Developers) 
Hi V J,

Try using UserShare object.
https://www.salesforce.com/developer/docs/api/Content/sforce_api_objects_usershare.htm

Let me know how it goes.

Thanks,
Pratik
v jv j
Needed Help in Using UserMembershipSharingRule in apex, Please Anybody  has any idea on this Please share...