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
MikeyOMikeyO 

Add sharing rule to cases

Is there a way to create a sharing rule for cases that says "Share with person in field name = Contact Name"

Background:
We use cases in the marketing department so that internal people can request work from us. However, once the request comes in it gets reassigned to an internal marketing person. So now the case owner is someone other than the person that originated it.
In order to keep track of the original requestor we use the standard look up field "Contact Name" and we have all our users as part of a contact list under the corporate account.

I would like to share the cases with the person in the 'Contact Name = John Doe" 
Is this possible?
If so, how would I accomplish this?
thank you!
Tyler Mowbrey 1Tyler Mowbrey 1
Hi Mikey,

Yes this is possible. Ultimately you would need to have a lookup from User to Contact to ensure that we know which user to share to. Then, you would need to create an apex trigger on cases and based upon the contact name having a related user, create a new share for the case/user. Here is a link to a great blog post on how to create sharing reasons programmatically: http://blog.jeffdouglas.com/2009/11/25/programmatically-creating-sharing-rules-with-apex/. Let me know if you have further questions.