• Steven Robert
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

Hi All,

 

I'm trying to create a record in salesforce, but I'm getting an exception as System.NullException.

 

using System;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Text;
using System.Net;
using System.IO;
using System.Xml;
using System.Data;
using sforce;

public partial class Example : System.Web.UI.Page
{
    private SforceService binding;
  
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }

    protected void btnClick(object sender, EventArgs e)
    {
        CreateAccountSample();
    }

    /// Demonstrates how to create one or more Account records via the API 

    public void CreateAccountSample()
    {
        Account account1 = new Account();
        Account account2 = new Account();

        account1.BillingCity = "Wichita";
        account1.BillingCountry = "US";
        account1.BillingState = "KA";
        account1.BillingStreet = "4322 Haystack Boulevard";
        account1.BillingPostalCode = "87901";

        account2.Name = textName.Text;
        account2.BillingCity = TextBox1.Text;
        account2.BillingCountry = TextBox2.Text;
        account2.BillingState = TextBox3.Text;
       
        sObject[] accounts = new sObject[2];
        accounts[0] = account1;
        accounts[1] = account2;
        
        try
        {
            SaveResult[] saveResults = binding.create(accounts);

            for (int i = 0; i < saveResults.Length; i++)
            {
               if (saveResults[i].success)
                {                   
                    Console.WriteLine("An Account was created with Id: {0}",
                        saveResults[i].id);
                }
                else
                {
                    Console.WriteLine("Item {0} had an error updating", i);
                   
                    foreach (Error error in saveResults[i].errors)
                    {
                        Console.WriteLine("Error code is: {0}",
                            error.statusCode.ToString());
                        Console.WriteLine("Error message: {0}", error.message);
                    }
                }
            }
        }
        catch (System.Web.Services.Protocols.SoapException e)
        {
            Console.WriteLine(e.Code);
            Console.WriteLine(e.Message);
        }
    } 

}

 

 

It would be appriciative if any one rectifies me where I'm going wrong.

 

thanks in advance.

Zubair