0

Is it feasible to create sharing rules through apex , not manual sharing of records?

Can someone please let me know if that can be done?

1

Not really. It's theoretically possible to do so, but not even Financialforce's MDAPI supports SharingRule. You would have to spend a significant amount of effort. For custom objects, you can use Apex Managed Sharing, and for standard objects, consider Apex-based manual sharing; it's relatively painless to perform in bulk, and is pretty easy to maintain. In fact, I've written a simple, but specialized, manual sharing application for my org. Depending on your needs, it's not too bad. Even then, I'd try to persuade you to look at alternative declarative options, like territory management, before you go down the dark path of automating sharing.

  • I found this article exactly depicting my case and it results in no ultimate success. developer.salesforce.com/forums/?id=906F0000000B28SIAS – Testing_SFDC Jan 12 '17 at 5:33
  • 1
    @SFDC_Learner You are not the first to try, and you won't be the last, but basically, until the mdapi is more accessible in Apex, you should consider it impossible for all practical purposes. Also, consider that creating sharing rules is an asynchronous process. An automated process could theoretically lock up your org's setup and configuration page for days (last sharing rule we created took 16 hours to complete). Given there's no way to abort it, either, I'd be wary of trying to do this. – sfdcfox Jan 12 '17 at 5:41
  • You mean manual sharing of records through share objects would be the best? – Testing_SFDC Jan 12 '17 at 5:50
  • 1
    @SFDC_Learner Yes, even though they say "Manual", because we can't select any of the other picklist types, they're generated by way of a trigger that maintains the correct sharing. To make things easier, we also have a process that creates Public Groups for everyone that a record should be shared with. It's specialized, but only admins have access to sharing buttons in our org, so it works out well. – sfdcfox Jan 12 '17 at 5:53

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.