// Create the request object and set the target and principal access
GrantAccessRequest grantRequest = new GrantAccessRequest()
{
Target = new EntityReference(Account.EntityLogicalName, accountId),
PrincipalAccess = new PrincipalAccess()
{
Principal = new EntityReference(SystemUser.EntityLogicalName, userId),
AccessMask = actionRights
}
};
// Execute the request.
GrantAccessResponse granted = (GrantAccessResponse)service.Execute(grantRequest);