function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
DjangoDjango 

I'm getting error "There is an error in XML document (1, 278)" when running a query

Hi.
 
I got from the API an example of how to connect and query SF for some data.  With data, I put together the following code.
 

try {

     //CREATES THE QUERY TO CALL SF WS

     string ls_Query = "SELECT FirstName,LastName,Email " +

                               "FROM Contact " +

                               "WHERE Id = '" + as_SFID + "'";

 

     //READS THE URL AND USER VALUES FROM THE WEB CONFIG

     string ls_SFURL = "https://test.salesforce.com/services/Soap/u/9.0";

     string ls_SFUser = "user";

     string ls_SFPassword = "password";

  

     //CREATES THE SF OBJECT

     SforceService lo_srvcSF = new SforceService();

     lo_srvcSF.Url = ls_SFURL;

 

    //LOGS TO THE SF WS

    LoginResult lo_SFLoginResult = lo_srvcSF.login(ls_SFUser,ls_SFPassword);

  

    //SAVES THE SESSION HEADER AND URL

    SessionHeader lo_SFSessionHeader = new SessionHeader();

    lo_SFSessionHeader.sessionId = lo_SFLoginResult.sessionId;

    lo_srvcSF.Url = lo_SFLoginResult.serverUrl;

    lo_srvcSF.SessionHeaderValue = lo_SFSessionHeader;

    string ls_SFUserID = lo_SFLoginResult.userId;

 

    //SENDS THE QUERY TO THE SF WS

    lo_srvcSF.QueryOptionsValue = new QueryOptions();

    lo_srvcSF.QueryOptionsValue.batchSize = 500;

    lo_srvcSF.QueryOptionsValue.batchSizeSpecified = true;

    QueryResult lo_QueryResult = null;

    lo_QueryResult = lo_srvcSF.query(ls_Query);

    if (lo_QueryResult == null)

          throw new Exception("The query retrieved a null result for the Contacts.");

     if (lo_QueryResult.size ==0)

          throw new Exception("The query retrieved cero records for the Contacts.");

 

     //GETS THE RECORDS RETRIEVED

     if (lo_QueryResult.size > 0)  {

           sObject[] lo_Records = lo_QueryResult.records;

           Contact lo_Contact = (Contact)lo_Records[0];

           as_FirstName = lo_Contact.FirstName;

           as_LastName = lo_Contact.LastName;

           as_EMail = lo_Contact.Email;

      }

}

catch(Exception Exp) {

     throw new Exception("Unable to read the details from Sales Force. The error was: " + Exp.Message);

}

 
When running this code, everything goes fine until line "lo_QueryResult = lo_srvcSF.query(ls_Query);".  The code is able to successful log to the WebServer, and properly assigns the session back, and everything.  But when it runs this line, I get an error saying "There is an error in XML document (1, 278)".  This doesn't say much.  Checking the innermessage it says "The specified type was not recognized: name='QueryResult', namespace='urn:partner.soap.sforce.com', at <result xmlns='urn:enterprise.soap.sforce.com'>.".  I compare this code with other one that works, and they are basically the same, but this one breaks.  I also tried getting that other code, and copy it, but breaks exactly the same.  I also tried in a different computer, with exactly the same error. 
 
Can someone please give me a  hand with this???
 
Regards
 
Victor
 
 
DjangoDjango
Hi  All.
 
In case any of you ever have this problem, I was able to solve it.  The problem was with the URL to aim to the server.
 
 
I was giving this URL to use, and I was getting that error.  The problem was with the part that says /u.  This part aims to the enterprise web service, and since I'm using the test server, I should use the partner web service, so it was a matter of changing the /u for /c.  I also changed the 9 to use version 7, and I no longer have this problem.  So the URL that worked for me was:
 
 
I hope this might help someone.
 
Regards
 
Victor
 
 
 
Jon L. DaviesJon L. Davies

Here is an excerpt from the API documents, page 28.

To access your organization’s Salesforce Sandbox via the API, use the following URLs to make login requests:

https://test.salesforce.com/services/Soap/c/9.0 (enterprise WSDL)

https://test.salesforce.com/services/Soap/u/9.0 (partner WSDL)

 

You should always try and stay current on your version numbers.  If you are coding something new you should always use the latest version.  There are VERY few times that you will need to stay on an older version, especially when you are coding something new.

The error you are getting is related to a type problem with QueryResult.  This is odd as QueryResult is in both the partner WSDL and the Enterprise WSDL.  You might want to download your WSDL again and rebuild your proxy class.

 

JonD

360 Vantage
3115 S. Price Road
Chandler, AZ 85248