You should register your plugin on account as you want to check the related cases of account. Below is the sample code:
if (context.InputParameters.Contains("Target") &&
context.InputParameters["Target"] is Entity)
{
//Obtain the target entity from the input parameters
Entity incident = (Entity)context.InputParameters["Target"];
//Verify that the target entity represents an account
//If not, this plug-in was not registered correctly
if (incident.LogicalName != "account")
return;
try
{
//Obtain the organisation service reference
IOrganizationServiceFactory serviceFactory =
(IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
QueryExpression query = new QueryExpression("incident");
query.ColumnSet = new ColumnSet(false);
query.Criteria.AddCondition(new ConditionExpression("customerid",ConditionOperator.Equal,context.PrimaryEntityId)
EntityCollection entityCollection = service.RetrieveMultiple(query);
throw new InvalidPluginExecutionException(entityCollection.Entities.Count.ToString());
}
catch (Exception ex)
{
tracingService.Trace("Fail while counting: {0}", ex.ToString());
throw;
}