• Django
  • NEWBIE
  • 0 Points
  • Member since 2006

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 1
    Replies
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
 
 
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 = "castiron@infousa.com";

string ls_SFPassword = "c@$T1r0n12";

string ls_DefaultSFUserID = "00560000000yHTo";

int li_SF_BATCH_SIZE = 500;

 

 

//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_srvcSF.query(ls_Query);

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;

}

else

{

//SINCE A CONTACT WAS NOT FOUND, THEN LOOKS FOR A LEAD

//CREATES THE QUERY TO CALL SF WS

ls_Query = "SELECT FirstName,LastName,Email " +

"FROM Lead " +

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

//SENDS THE QUERY TO THE SF WS

lo_QueryResult = lo_srvcSF.query(ls_Query);

if (lo_QueryResult == null)

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

if (lo_QueryResult.size ==0)

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

//GETS THE RECORDS RETRIEVED

sObject[] lo_Records = lo_QueryResult.records;

Lead lo_Lead = (Lead)lo_Records[0];

as_FirstName = lo_Lead.FirstName;

as_LastName = lo_Lead.LastName;

as_EMail = lo_Lead.Email;

}

}

catch(Exception Exp)

{

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

}

 
The
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 = "castiron@infousa.com";

string ls_SFPassword = "c@$T1r0n12";

string ls_DefaultSFUserID = "00560000000yHTo";

int li_SF_BATCH_SIZE = 500;

 

 

//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_srvcSF.query(ls_Query);

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;

}

else

{

//SINCE A CONTACT WAS NOT FOUND, THEN LOOKS FOR A LEAD

//CREATES THE QUERY TO CALL SF WS

ls_Query = "SELECT FirstName,LastName,Email " +

"FROM Lead " +

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

//SENDS THE QUERY TO THE SF WS

lo_QueryResult = lo_srvcSF.query(ls_Query);

if (lo_QueryResult == null)

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

if (lo_QueryResult.size ==0)

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

//GETS THE RECORDS RETRIEVED

sObject[] lo_Records = lo_QueryResult.records;

Lead lo_Lead = (Lead)lo_Records[0];

as_FirstName = lo_Lead.FirstName;

as_LastName = lo_Lead.LastName;

as_EMail = lo_Lead.Email;

}

}

catch(Exception Exp)

{

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

}

 
The
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