I'm trying to make a custom workflow on Dynamics CRM. I need to delete some entities when another entity is deleted.
I created my class library and I retrieved the Guid of the deleted entity with this code:
protected override void Execute(CodeActivityContext executionContext)
{
ITracingService tracingService = executionContext.GetExtension<ITracingService>();
IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
IOrganizationServiceFactory serviceFactory =
executionContext.GetExtension<IOrganizationServiceFactory>();
IOrganizationService service =
serviceFactory.CreateOrganizationService(context.UserId);
mService = service;
mExecutionContext = executionContext;
Guid myTipologyTypeDeleted = context.PrimaryEntityId;
bool isReading = context.PrimaryEntityName.Equals(new_tipologialettura_richiesta.EntityLogicalName);
bool isMaintenance = context.PrimaryEntityName.Equals(new_tipologiamanutenzionerichiesta.EntityLogicalName);
bool myResult = AddOnIntervention(isReading, isMaintenance, myTipologyTypeDeleted);
// Retrieve the summands and perform addition
result.Set(executionContext, myResult);
}
And here all works, I get the Guid and I get the type (reading or maintenance).
My problem is when I try to retrieve the entity with this code (the same code is working perfectly in another workflow started on record creation, but on record delete gives me error).
Entity myReadingEntity = mService.Retrieve(new_tipologialettura_richiesta.EntityLogicalName, myTipologyTypeDeleted, new ColumnSet(true));
Here I get an exception saying that no record of type MyType with id myId has been found.
I checked the record and it still exist in the DB so it has not been deleted. What I'm doing wrong?
Thanks