I am at on-prem environment of Dynamics CRM 2011, I want to enlist all those accounts to whom a user have read access. So far, I am just reach out to the following but it is by just checking if the user have ReadAcces. But I want to query once and populate all those accounts the user have read access.
private static bool retrieveReadAccess(IOrganizationService service, Guid userId, Guid avcId)
{
//retrieve user ReadAccess to account
RetrievePrincipalAccessRequest principalAccessReq = new RetrievePrincipalAccessRequest
{
Principal = new EntityReference("systemuser", userId),
Target = new EntityReference("account", avcId)
};
RetrievePrincipalAccessResponse principalAccessRes = (RetrievePrincipalAccessResponse)service.Execute(principalAccessReq);
if (principalAccessRes.AccessRights.HasFlag(AccessRights.ReadAccess))
{
return true;
}
return false;
}