Skip to content

Instantly share code, notes, and snippets.

@MitchMilam
Last active June 8, 2024 22:57
Show Gist options
  • Save MitchMilam/073dd212298b9d9a50fb4251780188e4 to your computer and use it in GitHub Desktop.
Save MitchMilam/073dd212298b9d9a50fb4251780188e4 to your computer and use it in GitHub Desktop.
Verify that a Dynamics 365 record exists
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