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

Bit Urgent, How to implement this scenario?

Hi, we have following requirement, please let me know how to achieve below functionality:

1. Admin creates a new product called PROD1.
    As soon as the new product PROD1 is created, a new Public Group PG1 will be created dynamically through the already existing trigger.
2. Then Admin adds USER2 and USER3 to the public group PG1(which is created in the above step1)
3. Now our req is to make all the users in that public group PG1(USER2 and USER3) to be able to access the product PROD1.How to achieve this functionality?

Thanks in advance.
Himanshu ParasharHimanshu Parashar
Hi Jaya,

you can share using apex sharing by inserting a record in share object.
      String GROUPID='your group id here';
      Custom__share jobShr= new Job__Share();
     // Set the ID of record being shared.
      jobShr.ParentId = recordId;
      // Set the ID of user or group being granted access.
      jobShr.UserOrGroupId = GROUPID;
      // Set the access level.
      jobShr.AccessLevel = 'Read';
      // Set rowCause to 'manual' for manual sharing.
      // This line can be omitted as 'manual' is the default value for sharing objects.
      jobShr.RowCause = Schema.custom__Share.RowCause.Manual;
      // Insert the sharing record and capture the save result. 
      // The false parameter allows for partial processing if multiple records passed 
      // into the operation.
      Database.SaveResult sr = Database.insert(jobShr,false);

Salesforce Certified Developer | Administrator | Service Cloud Consultant

P.S.  If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.
Thanks Himanshu for your reply; OWD for Product doesnt work and Product accessibility can be set only through profiles. So can you confirm if apex based sharing works for Product?
Himanshu ParasharHimanshu Parashar
Hi Jaya,

I thought that you are talking about any custom object called product. Standard Product object doens't have OWD. as this is standard SFDC behavior we can't do much.