Salesforce Decode
Salesforcedecode
Back to questions
ApexAdvancedsharingmanual-shareapex

Design Apex sharing calculation helpers for manual sharing

Real World Scenario

Partner deals require dynamic AccountShare rows based on complex territory and team rules.

Expected Answer

• Separate sharing service from trigger for testability • Bulk compute share rows comparing existing vs desired • Delete stale shares insert new in single transaction • Use rowCause custom for audit distinction • without sharing service class documented and reviewed • Batch recalc job when territory realignment occurs • Test as multiple users with UserInfo and runAs

Follow-Up Questions & Answers

Click to expand — each follow-up includes a direct, interview-ready answer

Main difference: use case and scale. Separate sharing service from trigger for testability. Bulk compute share rows comparing existing vs desired. Pick based on your integration pattern and team capability. Manual sharing at scale belongs in batch recalc—not synchronous trigger for 10k shares. Optimize for scale and operational observability.

Architect Perspective

Manual sharing at scale belongs in batch recalc—not synchronous trigger for 10k shares.