Skip to content

Instantly share code, notes, and snippets.

@furkankaracan
Created April 4, 2024 14:21
Show Gist options
  • Save furkankaracan/d8ab1405dc3dad9db4e8187c8e4903c0 to your computer and use it in GitHub Desktop.
Save furkankaracan/d8ab1405dc3dad9db4e8187c8e4903c0 to your computer and use it in GitHub Desktop.
/// <summary>
/// Shares a record with a principal
/// </summary>
/// <param name="service">Authenticated client implementing the IOrganizationService interface</param>
/// <param name="principal">The user, team, or organization to share the record with.</param>
/// <param name="access">The access rights to grant</param>
/// <param name="record">The record to share</param>
static void ShareRecord(
IOrganizationService service,
EntityReference principal,
AccessRights access,
EntityReference record)
{
PrincipalAccess principalAccess = new()
{
AccessMask = access,
Principal = principal
};
GrantAccessRequest request = new()
{
PrincipalAccess = principalAccess,
Target = record
};
service.Execute(request);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment