Updating a *__Share object with Skuid

  • 1
  • Question
  • Updated 4 years ago
  • Answered
Hi,

I want to automatically create a sharing rule as part of a button click with the sharing target determined from the data in a record.

I am wondering whether this can be done by creating a model on the *__Share object and inserting the appropriate record, perhaps via Javascript of the Action Framework?

Does anyone have any experience of this?  I could try an Apex trigger but I'd rather do it in Skuid if possible.

Thanks

Brad
Photo of Bradley Wood

Bradley Wood

  • 424 Points 250 badge 2x thumb

Posted 4 years ago

  • 1
Photo of J.

J., Official Rep

  • 7,470 Points 5k badge 2x thumb
Brad,

This is possible with Skuid, and you are on the right track. Create a model on your share object and insert records into it like you would any other model. Just like you would in your trigger, you'll have to populate AccessLevel, UserOrGroupId, ParentId (or [StandardObject]Id for standard objects) and RowCause. If you want to use the same RowCause for every record inserted, set a condition on your __Share model that sets it to the appropriate value. It looks like all the objects share the same RowCause Picklist (meaning you'll see every option every time), so using that condition seems like a good idea, if you can get away with it. Otherwise, you'll have to use a custom field renderer to limit the options.

You can use the Skuid Actions Framework to create the row in the Share model. For instance, say you have a table of Accounts and you want to use a row action to open a popup or drawer containing Share records, or you've got a Page Title on a detail page and you want a "Create Sharing Record" button which opens a popup to fill in the details. You can also create them inline in a table (e.g. you're on an Account detail page and you have a table of the related Share records), or if the logic should really be handled programmatically, there's always the trusty snippet.

Does that help?
Photo of Bradley Wood

Bradley Wood

  • 424 Points 250 badge 2x thumb
That sounds good, and workable, thanks J. I'll give it a go.

Brad
Photo of Bradley Wood

Bradley Wood

  • 424 Points 250 badge 2x thumb
So I got this to work without too much trouble. 
I did it as follows:
  • created an Apex Sharing Reason on the Custom Object
  • created a model on the __share object
  • set conditions as shown.
  • made the model create a row if one didn't exist.
  • using the action framework saved the model associated with the __share object

For those who want to understand this in more details, this page is useful. 
When setting the condition for the RowCause, you must remember to use the Name of the apex sharing reason you created previously appended with __c.
(Edited)
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Thanks for documenting your solution so that others can use it.  Well done...