Get all user/team an object (account/contact/lead) is shared with using OrganizationService service.
public void ProcessSharedUser()
{
PrincipalAccess[] sharedUsersOfAccount = getSharedUsersforAccount("account", accountId, service);
if (sharedUsersOfAccount.Length > 0)
{
for (int i = 0; i < sharedUsersOfAccount.Length; i++)
{
Guid user = sharedUsersOfAccount[i].Principal.Id;
// define your logic here
}
}
}
public PrincipalAccess[] getSharedUsersforAccount(string entityName, Guid accountId, IOrganizationService service)
{
RetrieveSharedPrincipalsAndAccessRequest retrieveSharedRequest = new RetrieveSharedPrincipalsAndAccessRequest()
{
Target = new EntityReference(entityName, accountId)
};
RetrieveSharedPrincipalsAndAccessResponse retrieveSharedResponse = (RetrieveSharedPrincipalsAndAccessResponse)service.Execute(retrieveSharedRequest);
return retrieveSharedResponse.PrincipalAccesses;
}
public void ProcessSharedUser()
{
PrincipalAccess[] sharedUsersOfAccount = getSharedUsersforAccount("account", accountId, service);
if (sharedUsersOfAccount.Length > 0)
{
for (int i = 0; i < sharedUsersOfAccount.Length; i++)
{
Guid user = sharedUsersOfAccount[i].Principal.Id;
// define your logic here
}
}
}
public PrincipalAccess[] getSharedUsersforAccount(string entityName, Guid accountId, IOrganizationService service)
{
RetrieveSharedPrincipalsAndAccessRequest retrieveSharedRequest = new RetrieveSharedPrincipalsAndAccessRequest()
{
Target = new EntityReference(entityName, accountId)
};
RetrieveSharedPrincipalsAndAccessResponse retrieveSharedResponse = (RetrieveSharedPrincipalsAndAccessResponse)service.Execute(retrieveSharedRequest);
return retrieveSharedResponse.PrincipalAccesses;
}
No comments:
Post a Comment