Skip to content

Instantly share code, notes, and snippets.

@JitendraZaa
Created February 13, 2019 01:51
Show Gist options
  • Save JitendraZaa/f973e500b6ee5e83995c367b7e1a54a8 to your computer and use it in GitHub Desktop.
Save JitendraZaa/f973e500b6ee5e83995c367b7e1a54a8 to your computer and use it in GitHub Desktop.
Apex based sharing of Opportunity using Territory
String territoryId = 'valid Territory Id';
String oppId = 'valid Opp Id';
Group g = [Select ID FROM Group Where relatedId=:territoryId LIMIT 1];
Opportunityshare oppShare = new Opportunityshare();
oppShare.opportunityid = oppId;
oppShare.UserOrGroupId = g.Id;
oppShare.OpportunityAccessLevel = 'Read';
oppShare.RowCause = 'Manual';
insert oppShare;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment