Still facing error please help me for this.
Error:- System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]: An exception System.FormatException was thrown while trying to convert input value '[REDACTED]' to attribute 'quote.opportunityid'. Expected type of attribute value: System.Guid. Exception raised: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx). (Fault Detail is equal to Exception details:
ErrorCode: 0x80040224
Message: An exception System.FormatException was thrown while trying to convert input value '[REDACTED]' to attribute 'quote.opportunityid'. Expected type of attribute value: System.Guid. Exception raised: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
TimeStamp: 2023-05-18T13:03:11.3085608Z
OriginalException: PluginExecution
ExceptionSource: PluginExecution
--
).
Code:-
case "Delete_20":
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is EntityReference && context.MessageName == "Delete")
{
tracer.Trace("hi1");
target = context.InputParameters["Target"] as Entity;
tracer.Trace("hi2");
EntityReference opportunityReference = context.InputParameters["Target"] as EntityReference;
GetDraftQuote(opportunityReference, service);
tracer.Trace("hi3");
}
break;
default:
break;
private void GetDraftQuote(EntityReference opportunityReference, IOrganizationService service)
{
string Query = @"<fetch>" +
"<entity name='quote'>" +
"<attribute name='opportunityid' />" +
"<attribute name='statecode' />" +
"<filter type='and'>" +
"<condition attribute='opportunityid' operator='eq' value='" + opportunityReference + "' />" +
"<condition attribute='statecode' operator='eq' value='0' />" +
"</filter>" +
"</entity>" +
"</fetch>";
EntityCollection result = service.RetrieveMultiple(new FetchExpression(Query));
if (result.Entities.Count > 0)
{
throw new InvalidPluginExecutionException("Delete an opportunity with draft quotes is not allowed.");
}
}