0

I have one requirement where it should allows users access to the cases they request. The OWD is set to private and we created several case sharing rule's to grand access tousers to see all cases. system admins should to be able to see all cases and the requester should be able to see his or her case. How we can implement this? Please help.

  • Are the Requesters internal (Salesforce users) or external (community users) to Salesforce? – Dave Humm Oct 25 '16 at 14:26
  • @Dave- Requesters are Internal users. – Sofiya Oct 25 '16 at 14:44
  • That will take Apex sharing as normal sharing rules don't allow it. – Dave Humm Oct 25 '16 at 15:20
0

You can provide the Case creator with an additional Read/Write access using an Apex trigger or process builder.

Below is sample code

 trigger ShareWithReportingMng on Case (after insert) {
    List<CaseShare> csShareList = new List<CaseShare>();
    for( Case cs : trigger.new ) {
        if( cs.Reports_to__c != NULL ) {
            // Create a new caseShare object for each case where reports_to__c field is not NULL.
            CaseShare csShare = new CaseShare();
            // Give Read write access to that user for this particular case record.
            csShare.CaseAccessLevel = 'edit';
            // Assign case Id of case record.
            csShare.CaseId = cs.id;
            // Assign user id to grant read write access to this particular case record.
            csShare.UserOrGroupId = cs.Reports_to__c;
            csShareList.add( csShare );
        }
    }
    if( csShareList != null && csShareList.size() != 0 ) {
        try {
            insert csShareList;
        }catch( Exception e ) {
            trigger.new[0].Reports_to__c.addError('Error::::::'+e.getMessage());
        }
    }
}

For more info on sharing a record using apex please check below link

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_bulk_sharing_creating_with_apex.htm

Check below link for sharing record using process builder

https://automationchampion.com/tag/programmatically-creating-sharing-rules-with-apex/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.