Step 1: First create the salesforce API. Please refer to my my previous post.
Step 2: Try this sample code:
//Verify that we are already authenticated, if not
//call the login function to do so
try
{
Account account;
sObject[] accs = new sObject[1];
for (int j = 0; j < accs.Length; j++)
{
account = new Account();
if (accounts == null)
account.AccountNumber = "0000000";
else
account.AccountNumber = "000000" + (accounts.Length + 1);
account.BillingCity = "CERRITOS";
account.BillingCountry = "US";
account.BillingState = "CA";
account.BillingStreet = "4322 Firstland";
account.BillingPostalCode = "90703";
account.Description = "Software and Services";
account.Fax = "511.111.1234";
account.Industry = "Software";
account.Name = "AmaSoft";
account.NumberOfEmployees = 40;
account.Ownership = "Amar";
account.Phone = "999.111.2222";
account.Website = "https://crmhunt.com";
accs[j] = account;
}
//create the object(s) by sending the array to the web service
SaveResult[] sr = binding.create(accs);
for (int j = 0; j < sr.Length; j++)
{
if (sr[j].success)
{
Console.WriteLine("An account was create with an id of: " + sr[j].id);
//save the account ids in a class array
if (accounts == null)
{
accounts = new string[] { sr[j].id };
}
else
{
string[] tempAccounts = null;
tempAccounts = new string[accounts.Length + 1];
for (int i = 0; i < accounts.Length; i++)
tempAccounts[i] = accounts[i];
tempAccounts[accounts.Length] = sr[j].id;
accounts = tempAccounts;
}
}
else
{
//there were errors during the create call, go through the errors
//array and write them to the screen
for (int i = 0; i < sr[j].errors.Length; i++)
{
//get the next error
Error err = sr[j].errors[i];
Console.WriteLine("Errors were found on item " + j.ToString());
Console.WriteLine("Error code is: " + err.statusCode.ToString());
Console.WriteLine("Error message: " + err.message);
}
}
}
Console.WriteLine("\nHit return to continue...");
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine("\nFailed to create account, error message was: \n"
+ ex.Message);
Console.Write("\nHit return to continue...");
Console.ReadLine();
}