Unshare Record in CRM using C#

Hi,

Here is the code for un sharing record in CRM using C# code.

///


/// Un shares the Record from Team or User.
///


/// CRM Organization Service
/// Target Entity Reference
/// Team or User Entity Reference

public void UnShareRecord(IOrganizationService service, EntityReference erfTargetEntity, EntityReference erfTeamOrUser)
{
       ModifyAccessRequest modif = new ModifyAccessRequest();
       modif.Target = erfTargetEntity;
       PrincipalAccess principal = newPrincipalAccess();
       principal.Principal = erfTeamOrUser;
       principal.AccessMask = AccessRights.None;
       modif.PrincipalAccess = principal;
       ModifyAccessResponse modif_response = (ModifyAccessResponse)service.Execute(modif);
}

Refer this link for sharing record.

Hope this helps.


Happy CRM’ing
Gopinath

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s