You need to sign in to do that
Don't have an account?
RajeevKumar
C# querySample - Sample code not working
Guys
I am new to sales force webservices , I can login to server but not able to query on database. Getting Following error
Please help.
Compiler Error Message: CS0103: The name 'binding' does not exist in the current context
Source Error:
Line 57: {
Line 58: QueryResult qr = null;
Line 59: binding.QueryOptionsValue = new sforce.QueryOptions();
Line 60: binding.QueryOptionsValue.batchSize = 250;
Line 61: binding.QueryOptionsValue.batchSizeSpecified = true;
source code is
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using sforce;
public partial class Default2 : System.Web.UI.Page
{
public SforceService sfdc = new SforceService();
private LoginResult loginResult = null;
protected void Page_Load(object sender, EventArgs e)
{
logininfo();
querySample();
}
private void logininfo()
{
sfdc = new SforceService();
try
{
LoginResult lr = sfdc.login("xxxxxx", "xxxxxxx");
sfdc.Url = lr.serverUrl;
sfdc.SessionHeaderValue = new SessionHeader();
sfdc.SessionHeaderValue.sessionId = lr.sessionId;
//Displaying the Session ID and URL
Label1.Text = "The session id is: " + lr.sessionId;
Label1.Text += "
The new server url is: " + lr.serverUrl;
//Displaying the user Details
GetUserInfoResult userResults = new GetUserInfoResult();
userResults = sfdc.getUserInfo();
Label1.Text += "
User Name : " + userResults.userFullName;
Label1.Text += "
User Email : " + userResults.userEmail;
//Label1.Text += "
User License : " + userResults.licenseType;
}
catch (Exception exp)
{
Label1.Text = exp.ToString();
}
}
private void querySample()
{
QueryResult qr = null;
binding.QueryOptionsValue = new sforce.QueryOptions();
binding.QueryOptionsValue.batchSize = 250;
binding.QueryOptionsValue.batchSizeSpecified = true;
qr = binding.query("select FirstName, LastName from Contact");
bool bContinue = true;
int loopCounter = 0;
while (bContinue)
{
Console.WriteLine("\nResults Set " + Convert.ToString(loopCounter++)
+ " - ");
//process the query results
for (int i=0;i {
sforce.sObject con = qr.records[i];
string fName = con.Any[0].InnerText;
string lName = con.Any[1].InnerText;
if (fName == null)
Console.WriteLine("Contact " + (i + 1) + ": " + lName);
else
Console.WriteLine("Contact " + (i + 1) + ": " + fName
+ " " + lName);
}
//handle the loop + 1 problem by checking the most recent queryResult
if (qr.done)
bContinue = false;
else
qr = binding.queryMore(qr.queryLocator);
}
Console.WriteLine("\nQuery succesfully executed.");
Console.Write("\nHit return to continue...");
Console.ReadLine();
}
}
I am new to sales force webservices , I can login to server but not able to query on database. Getting Following error
Please help.
Compiler Error Message: CS0103: The name 'binding' does not exist in the current context
Source Error:
Line 57: {
Line 58: QueryResult qr = null;
Line 59: binding.QueryOptionsValue = new sforce.QueryOptions();
Line 60: binding.QueryOptionsValue.batchSize = 250;
Line 61: binding.QueryOptionsValue.batchSizeSpecified = true;
source code is
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using sforce;
public partial class Default2 : System.Web.UI.Page
{
public SforceService sfdc = new SforceService();
private LoginResult loginResult = null;
protected void Page_Load(object sender, EventArgs e)
{
logininfo();
querySample();
}
private void logininfo()
{
sfdc = new SforceService();
try
{
LoginResult lr = sfdc.login("xxxxxx", "xxxxxxx");
sfdc.Url = lr.serverUrl;
sfdc.SessionHeaderValue = new SessionHeader();
sfdc.SessionHeaderValue.sessionId = lr.sessionId;
//Displaying the Session ID and URL
Label1.Text = "The session id is: " + lr.sessionId;
Label1.Text += "
The new server url is: " + lr.serverUrl;
//Displaying the user Details
GetUserInfoResult userResults = new GetUserInfoResult();
userResults = sfdc.getUserInfo();
Label1.Text += "
User Name : " + userResults.userFullName;
Label1.Text += "
User Email : " + userResults.userEmail;
//Label1.Text += "
User License : " + userResults.licenseType;
}
catch (Exception exp)
{
Label1.Text = exp.ToString();
}
}
private void querySample()
{
QueryResult qr = null;
binding.QueryOptionsValue = new sforce.QueryOptions();
binding.QueryOptionsValue.batchSize = 250;
binding.QueryOptionsValue.batchSizeSpecified = true;
qr = binding.query("select FirstName, LastName from Contact");
bool bContinue = true;
int loopCounter = 0;
while (bContinue)
{
Console.WriteLine("\nResults Set " + Convert.ToString(loopCounter++)
+ " - ");
//process the query results
for (int i=0;i {
sforce.sObject con = qr.records[i];
string fName = con.Any[0].InnerText;
string lName = con.Any[1].InnerText;
if (fName == null)
Console.WriteLine("Contact " + (i + 1) + ": " + lName);
else
Console.WriteLine("Contact " + (i + 1) + ": " + fName
+ " " + lName);
}
//handle the loop + 1 problem by checking the most recent queryResult
if (qr.done)
bContinue = false;
else
qr = binding.queryMore(qr.queryLocator);
}
Console.WriteLine("\nQuery succesfully executed.");
Console.Write("\nHit return to continue...");
Console.ReadLine();
}
}
string fName = con.Any[0].InnerText;
Compiler Error Message: CS0117: 'sforce.sObject' does not contain a definition for 'Any'
Please help.
scroll down to the .NET section.
please help
'sforce.sObject' does not contain a definition for 'Any'
Source Error:
Line 108: {
Line 109: sforce.sObject con = qr.records[i];
Line 110: string fName = con.Any[0].InnerText;
Line 111: string lName = con.Any[1].InnerText;
Line 112: if (fName == null)