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 HummCommented Oct 25, 2016 at 14:26
-
@Dave- Requesters are Internal users.– SofiyaCommented Oct 25, 2016 at 14:44
-
That will take Apex sharing as normal sharing rules don't allow it.– Dave HummCommented Oct 25, 2016 at 15:20
Add a comment
|
1 Answer
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
Check below link for sharing record using process builder
https://automationchampion.com/tag/programmatically-creating-sharing-rules-with-apex/