private Guid GetLatestHistoryId(IOrganizationService service, string targetName, Guid targetId) { var finalTargetName = targetName.Contains("_") ? targetName : $"clabs_{targetName}"; var entityName = "clabs_bpfchangehistory"; var searchFields = new string[] { $"{finalTargetName}id" }; var searchValues = new object[] { targetId }; var columns = new ColumnSet("clabs_bpfchangehistoryid", "createdon"); var desc = "createdon"; var result = SDKHelper.RetrieveEntityCollection(service, entityName, searchFields, searchValues, columns, ConditionOperator.Equal, desc); _tracingService.Trace($"Result Count: {result.Entities.Count}"); if (result.Entities.Count > 0) { _tracingService.Trace($"Result Id: {result[0].Id.ToString()}"); return(result[0].Id); } return(new Guid()); }