I am trying to update a field on all associated accounts. I am interested in the middle entity that links to the events of the past. The problem is that my linq query will return all records except the ones associated with the case. My plugin is running in pre-operation so I am not sure why this occurring. When I query the related records using LinqPad, I will not return the related records. I am using tracing to debug and I have proved that I am pulling the id for the case to be deleted. I changed my query fr om == to! To prove that the query was pulling records from the correct table. Any insight will be most appreciated.for this I searched to watch
Protected void ExecutePreCaseDelete (LocalPluginContext localContext)
{
if (localContext == null)
{
throw new ArgumentNullException ("localContext");
}
IPluginExecutionContext context = localContext.PluginExecutionContext;
IOrganizationService service = localContext.OrganizationService;
ITracingService tracingService = localContext.TracingService;
TracingService.Trace ("Implemented tracing service succesfully!");
Entity entity = null;
New_matter_case deletedCase = null;
Int totalCases = 0;
If (context.InputParameters.Contains ("Target") && context.InputParameters ["Target"] is Entity)
{
entity = context.InputParameters ["Target"] as Entity;
}
Else
{
if (context.MessageName == "Delete")
{
EntityReference entityRef = context.InputParameters ["Target"] as EntityReference;
DeletedCase = service.Retrieve (new_matter_case.EntityLogicalName, entityRef.Id, new ColumnSet (true)). ToEntity <new_matter_case> ();
}
Else
{
return;
}
}
If (deletedCase.new_AccountLink! = Null && deletedCase.new_AccountLink.LogicalName == Account.
Foreach (var account in accounts)
{
var cases = from c in orgContext.new_new_matter_case_accountSet
join d in orgContext.new_matter_caseSet on c.new_matter_caseid equals d.new_matter_caseId
wh ere c.accountid == account
&& c.new_matter_caseid! = DeletedCase.new_matter_caseId
select new new_new_matter_case_account
{
Id = c.Id
};
TotalCases = cases.ToList (). Count;
If (totalCases> 0)
{
Account updateAccount = service.Retrieve (Account.EntityLogicalName, account.Value, new ColumnSet (true)). ToEntity <Account> ();
UpdateAccount.new_CaseLitigation = true;
Service.Update (updateAccount);
}
Else
{
Account updateAccount = service.Retrieve (Account.EntityLogicalName, account.Value, newColumnSet (new string [] {"new_Caselitigation"})). ToEntity <Account> ();
UpdateAccount.new_CaseLitigation = false;
Service.Update (updateAccount);
};};
}
}
}
}
}
}