title: MS Dynamics CRM. Get users who current record shared with
body: <p>I have a entity record which is shared with or more users. I would like to unshare this record when Deactivate it. I want to do that in Plugin. But I can't understand how to get all users from sharing list who have access to this record. How to do that?</p>
  
  <p>Here is my code snippet:</p>
  
  <pre class="lang-cs prettyprint-override"><code>    protected void ExecutePostPersonSetStateDynamicEntity(LocalPluginContext localContext)
      {
          if (localContext == null)
          {
              throw new ArgumentNullException("localContext");
          }
  
          var context = localContext.PluginExecutionContext;
  
          var targetEntity = (Entity)context.InputParameters["EntityMoniker"];
          var state = (OptionSetValue)context.InputParameters["State"];
          var columns = new ColumnSet(new[] { "statecode" });
  
          var retrivedEntity = localContext.OrganizationService.Retrieve(targetEntity.LogicalName, targetEntity.Id, columns);
  
          if (state.Value == 1)
          {
              RevokeAccessRequest revokeRequest = new RevokeAccessRequest()
              {
                  Target = new EntityReference(personEntity.LogicalName, personEntity.Id),
                  Revokee = new EntityReference(neededEntity.LogicalName, needed.Id)
              };
  
              // Execute the request.
          }
      }
  </code></pre>
  
  <p>As you can see, I need an entity "neededEntity", I don't know how to get it from "targetEntity" or "retrievedEntity".</p>