1

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:

All three validation errors

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();
    }

2 Answers 2

0

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.

3
  • I had already read through this information. There is only one mention of the user-defined validation rules (whether or not the request is from the UI). Additionally, I can tell that the validation rules are getting run (since I get a validation error). The problem is that I am only getting ONE of the THREE errors that I expect. I don't see how the timing would affect the number of errors that I get once the rules are run.
    – NHLeo
    Commented Mar 21, 2014 at 16:07
  • My bad, you are right. The validation rules are only run once, at step 4 in the overview. This looks like a shortcoming in the SOAP API. The SaveResult contains a List of errors, but only the first one is filled with the first error. I wonder what SF will tell you if you submit this as a bug. Commented Mar 21, 2014 at 16:31
  • Hope you don't mind that I update my answer, to prevent others from spending unnecessary time on my wrong inputs.. Commented Mar 21, 2014 at 16:35
0

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .