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
PauloPaulo 

Submitting a lead to Salesforce

Hi,

I am trying to submit a lead to salesforce with asp.net in c# and am not having any luck. The code below executes fine but nothing is getting submitted to my salesforce development site. What login and pwd am I suppose to be using and what access rights should the login have? Am I missing something? When I execute the code below it does not return an id with saveResults.

private void createLead() {

//Create the proxy binding and login

sforce.SforceService binding = new sforce.SforceService();

sforce.LoginResult lr = binding.login("login", "pwd");

binding.SessionHeaderValue = new sforce.SessionHeader();

binding.SessionHeaderValue.sessionId = lr.sessionId;

binding.Url = lr.serverUrl;

// Create an account object to send to the service

Credco.Web.SignUp.sforce.Lead sfLead = new Credco.Web.SignUp.sforce.Lead();

// Set several properties

sfLead.FirstName = "Test";

sfLead.LastName = "Tester";

sfLead.LeadSource = "Testing";

// Add the account to an array of SObjects

sforce.sObject[] records = new sforce.sObject[] {sfLead};

// Invoke the create call, passing in the account properties

// and saving the results in a SaveResult object

sforce.SaveResult[] saveResults = binding.create(records);

// Access the new ID

String newID = saveResults[0].id;

}

SuperfellSuperfell
SaveResults includes an errors collection, look at the message field in that to see what error its giving you.

sforce.SaveResult [] sr = binding.create(records);
for ( int i = 0 ; i < sr.Length; i++)
{
if (sr[i].success)
Console.WriteLine("{0} Id of new account is {1}", i, sr[i].id);
else
Console.WriteLine("{0} Error creating account : {1}", i,sr[i].errors[0].message);
ids[i] = sr[i].id;
}
PauloPaulo

That worked. Company was a required field that I was not passing in. Thanks for all of your help Simon.