I am executing a plugin synchronously postOperation. I create an entity using IOrganizationService.create. This works, I get a GUID and I can see that the record exists in the CRM. Right after this, I am trying to retrieve the same record using same IOrganizationService and the GUID returned by the create call:
public void Execute(IServiceProvider serviceProvider) { ITracingService tracer = (ITracingService)serviceProvider.GetService(typeof(ITracingService)); IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); tracer.Trace("context is " + context.InputParameters["Target"]); context.OutputParameters["Message"] = "in plugin"; if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is EntityReference) { /* some other processing here . . */ Guid polId = service.Create(policy); Entity polEntity = service.Retrieve("new_customEntiry", polId, new ColumnSet(true));
But the polEntity.Id is null. polEntity["someattribute"] is also null .
Why is the retrieve call not working? What am I missing?
Thanks in advance!
Original post: stackoverflow.com/.../error-not-able-to-retrieve-after-create-in-plugin