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
surya123surya123 

Apex sharing rules on public groups

Hi,

 

  I have a requirement to share the custom object record with a public group based on certain criteria.

for example if the record is being created by salesrep who belongs to newyork city, i have to share this record with the public group which contains all the salesreps of newyork city. all public groups for respective cities are already created in the organizations.

 

Can some one help me how can i query the public group based on certain criteria in this scenario.

 

Please provide sample code.

 

Thanks

 

Anand@SAASAnand@SAAS

those were Two options:

Option 1: Have a naming convention for your public groups that help you to query using the Name. For e.g.

 

 

select Id,Name from Group where Name='NEW_YORK Group'

 

 Option 2: Have a custom object that maps the Criteria to the Group Id. So whenever you want to share you query this custom object get the group id and then create the sharing record.

 

surya123surya123

Anand,

 

Thanks for your reply. The query that you have mentioned will not work for me since i need to share the record with public group dynamically. I cannot hard code the group name in the query. based on city names i need to get the group id dynamically to share the record.

 

Is there any alternative other than going for a custom object.

 

Thanks