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
Max BachmanMax Bachman 

Why this doesent work?

using System;
using System.Collections.Generic;
using System.Text;
using WSDL.com.salesforce.Enterprise;

namespace WSDL
{
class MainFunction
{
static void Main()
{
SforceService connection = new SforceService();
LoginResult sfLoginResult = connection.login("XXX, "XXX");


connection.Url = sfLoginResult.serverUrl;
connection.SessionHeaderValue = new SessionHeader();
connection.SessionHeaderValue.sessionId = sfLoginResult.sessionId;

Lead sfLead = new Lead();

sfLead.FirstName = "Mayer";
sfLead.LastName = "asdasd";
sfLead.Company = "asdas";
sfLead.Title = "asdas";
sfLead.Phone = "asdas";
sfLead.Email = "asdas";
sfLead.State = "asdas";
sfLead.LeadSource = "Web";


SaveResult[] sr = connection.create(new sObject[] { sfLead });

Console.ReadKey(true);
}
}
}

SuperfellSuperfell

the returned SaveResult will indicate the new record's Id, or tell you what error happened that caused it to not create the record, so start by looking at that. Otherwise you'll have to describe how its not working.

Keyur PatelKeyur Patel

Hello,

 

Is there any error you get while you run application? Can you please provide more details?

 

Regards,

Keyur Patel

Don HobsonDon Hobson

Try adding something like this after SaveResult

 

SaveResult[] sr = connection.create(new sObject[] { sfLead });

 

// Check results.

for (int i = 0; i < sr.Length; i++)

{

  if (sr[i].success)

    {

      Console.WriteLine("Successfully created Object: " + sr[i].id);

    }

    else

   {

    Console.WriteLine("Error: could not create sobject " + "for array element " + i + ".");

    Console.WriteLine(" The error reported was: " + sr[i].errors[0].message + "\n");

   }

}