+ Start a Discussion

Help! C# and inserting new lead/account

I have seen many code samples here using binding.xxxxx - everytime I have tried this I get "The name binding does not exist in this context".


Sample code I am using (and I put Using System.data at top)


 Account account1 = new Account();
            Account account2 = new Account();
            // Set some fields on the account1 object. Name field is not set
            // so this record should fail as it is a required field.
            account1.BillingCity = "Wichita";
            account1.BillingCountry = "US";
            account1.BillingState = "KA";
            account1.BillingStreet = "4322 Haystack Boulevard";
            account1.BillingPostalCode = "87901";
            // Set some fields on the account2 object
            account2.Name = "Golden Straw";
            account2.BillingCity = "Oakland";
            account2.BillingCountry = "US";
            account2.BillingState = "CA";
            account2.BillingStreet = "666 Raiders Boulevard";
            account2.BillingPostalCode = "97502";
            // Create an array of SObjects to hold the accounts
            sObject[] accounts = new sObject[2];
            // Add the accounts to the SObject array
            accounts[0] = account1;
            accounts[1] = account2;
            // Invoke the create() call
          SaveResult[] saveResults = binding.create(accounts);


binding is the object that you are using to log against.


You should have declare it with a similar line that one.


SforceService binding = new SforceService();

Mark SFMark SF

See "C# Sample Code" in

http://www.salesforce.com/us/developer/docs/api/index_Left.htm#StartTopic=Content/sforce_api_quickstart_steps.htm#step_4_walk_through_the_sample_code for a full end-to-end sample that creates the binding variable. The other samples are only snippets and assume that you've already created the binding variable.




“binding” is an object of Salesforce web service, it has to be created in the way shown below and then login to your salesforce account using password and username.
SforceService binding = new SforceService();
LoginResult lr = binding.login("username","password");
  if (!lr.passwordExpired)
      // Reset the SOAP endpoint to the returned server URL  
      binding.Url = lr.serverUrl;
      // Create a new session header object  
     // Add the session ID returned from the login  
     binding.SessionHeaderValue = new SessionHeader();
     binding.SessionHeaderValue.sessionId = lr.sessionId;
     GetUserInfoResult userInfo = lr.userInfo;
    Console.WriteLine("Your password is expired.");

For further reference go to :


Salesforce Developer Support

If my answer solved your question, please mark it solved so I can help as many community members as possible!