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
hareeshnhareeshn 

how to share a record to role hierarchy using apex and visual force

Hi    for example role hierarchy  CEO----> projectmanager ---->projectlead 

if am sharing a record with projectmanager only CEO and Projectmanger able to see that record not projectlead How to achive this functionality using apex and visual force any ideas  will be appreciated thanks 
Best Answer chosen by hareeshn
Ramu_SFDCRamu_SFDC
The below salesforce article shows how to share the record through APEX. 
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_bulk_sharing_creating_with_apex.htm

Since your requirement is to share the records to Role rather than user or group, you might need to create a publicgroup and add the users of particular role. This way you can add a groupid which mimics the role. The below post has more information on this.
https://developer.salesforce.com/forums/ForumsMain?id=906F00000008xacIAA

All Answers

Ramu_SFDCRamu_SFDC
The below salesforce article shows how to share the record through APEX. 
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_bulk_sharing_creating_with_apex.htm

Since your requirement is to share the records to Role rather than user or group, you might need to create a publicgroup and add the users of particular role. This way you can add a groupid which mimics the role. The below post has more information on this.
https://developer.salesforce.com/forums/ForumsMain?id=906F00000008xacIAA
This was selected as the best answer
hareeshnhareeshn
Thanks for reply