Last active
June 8, 2024 22:57
-
-
Save MitchMilam/073dd212298b9d9a50fb4251780188e4 to your computer and use it in GitHub Desktop.
Verify that a Dynamics 365 record exists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static bool DoesRecordExist(IOrganizationService crmService, string entityName, Guid id) | |
{ | |
try | |
{ | |
crmService.Retrieve(entityName, id, new ColumnSet()); | |
} | |
catch (Exception ex) | |
{ | |
if (ex is FaultException<OrganizationServiceFault> orgException) | |
{ | |
// https://learn.microsoft.com/en-us/power-apps/developer/data-platform/reference/web-service-error-codes | |
if (orgException.Detail.ErrorCode == -2147220969) | |
{ | |
return false; //Record does not exist | |
} | |
throw; | |
} | |
} | |
return true; //Record exists | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment