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();
}
Attribution to: NHLeo
Possible Suggestion/Solution #1
Well, this was actually my problem. My application has been around for a while and is still being built with version 25 of the WSDL. Once I updated the code to use version 29 of the WSDL, everything worked just fine.
Note: my analysis of this problem was hampered by the fact that the C# .NET examples from Salesforce (that I obtained from https://wiki.developerforce.com/page/Miscellaneous_.NET_Code_Samples - it's the console application) includes version 10 (10!) of the WSDL.
Attribution to: NHLeo
Possible Suggestion/Solution #2
This appears to be a shortcoming (i.e. bug) in the SOAP API. The SaveResult contains a List of errors, but only the first one is filled with the first error.
Attribution to: Guy Clairbois
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/30657