I am sending an update request (SOAP) using the Partner API. The update request is setting two fields to values that should trigger three different validation errors. When I set these values in the SFDC UI, I see all three errors at once:
Now, when I make this same update request using the SOAP API, I only get back one validation error. Why is this? (Example code is shown below).
Thanks!
Leo
private void updateOpportunityGetValidationErrorsSample()
{
//Verify that we are already authenticated, if not
//call the login function to do so
if (!loggedIn)
{
if (!login())
return;
}
try
{
//create the account object to hold our changes
apex.sObject updateOpportunity = new apex.sObject();
//need to have the id so that web service knows which account to update
updateOpportunity.Id = "006i0000003cCMv";
//set new values that should trigger the validation errors
// ********************************************************************************
// NOTE: updating the fields to these values should produce three validation errors
// 1) CurrentGenerators__c is not being set to "RevItUp"
// 2) MainCompetitors__c does not start with "XYZ"
// 3) MainCompetitors__c is less than 40 characters long
// ********************************************************************************
updateOpportunity.Any = new System.Xml.XmlElement[] { this.GetNewXmlElement("MainCompetitors__c", "abc"),
this.GetNewXmlElement("CurrentGenerators__c", "abc") };
updateOpportunity.type = "Opportunity";
//call the update passing an array of object
SaveResult[] saveResults = binding.update(new apex.sObject[] { updateOpportunity});
// ********************************************************************************
// NOTE:
// At this point, the saveResults contains only one Error - not the three validation
// errors that I would expect
// ********************************************************************************
//loop through the results, checking for errors
for (int j = 0; j < saveResults.Length; j++)
{
Console.WriteLine("Item: " + j);
if (saveResults[j].success)
Console.WriteLine("An opportunity with an id of: " + saveResults[j].id + " was updated.\n");
else
{
Console.WriteLine("Item " + j.ToString() + " had an error updating.");
Console.WriteLine(" The error reported was: " + saveResults[j].errors[0].message);
// ********************************************************************************
// NOTE:
// This should report 3 errors - it only reports 1
// ********************************************************************************
Console.WriteLine(" Total error count = " + saveResults[j].errors.Length + "\n");
}
}
}
catch (Exception ex)
{
Console.WriteLine("\nFailed to succesfully update an opportunity, error message was: \n"
+ ex.Message);
}
Console.WriteLine("\nHit return to continue...");
Console.ReadLine();
}