TransWikia.com

Apex "Manual" Sharing on Standard Object (Account): Sharing Gets Deleted

Salesforce Asked by J. Schreiber on November 25, 2021

We use a Customer Community to dispatch Work Orders to partners. The partners use Customer Community Plus licenses. We share the Work Order using a community sharing set, but we cannot share the account the same way – because multiple partners might work on multiple work orders to the same account and therefore all partners need access to the same account.

Because our organization wide external sharing model for Accounts is "Private", I must manually share these accounts. I tried a trigger-based solution that inserts AccountShare, but unfortunately, I cannot get it to work: The shares get created, the partner as access to the community, and approximately 15 to 30 minutes later the partner cannot access the account any more. When inspecting AccountShare in the developer console, the respective share is gone.

I understand, that "Manual" shares are highly volatile and I need to account for use cases like owner change. I did, and still the shares magically disappear. Can anybody tell me, why?

One Answer

When the owner changes, sharing calculations are performed sometime around the final commit, long after your triggers. This is what causes your shares to disappear despite your best efforts. You would need something like a future method or queueable to persist those changes correctly. That said, you might consider using Account Team Members, which tend to work well for your use case (probably).

Answered by sfdcfox on November 25, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP