In a workflow step in CRM 2011, I must get the entity logical name of the record using URL of that record.
I get the GUID from url and then i used this method to get the logical name:
RetrieveAllEntitiesRequest allEntitiesRequest = new RetrieveAllEntitiesRequest(); allEntitiesRequest.EntityFilters = EntityFilters.Entity; allEntitiesRequest.RetrieveAsIfPublished = true; RetrieveAllEntitiesResponse allEntitiesResponse = (RetrieveAllEntitiesResponse)IOrgService.Execute(allEntitiesRequest); string entityLogicalName = string.Empty; foreach (EntityMetadata entityMetadata in allEntitiesResponse.EntityMetadata) { try { // Try to retrieve the record from the current entity Entity test = IOrgService.Retrieve(entityMetadata.LogicalName, objectguid, new Microsoft.Xrm.Sdk.Query.ColumnSet(true)); // if the previous instruction didn't throw an exception means that the record exists. entityLogicalName = entityMetadata.LogicalName; break; } catch { } }
But, this method has overload of loading and retrieving, and in case of actitvities has some bugs.
what is better solution to this problem?