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
ppatppat 

Please Someone Provide Batch Insert/update example!!

Hi All ,

I am new to salesforce and programming. I am trying to Batch insert/update accounts using C#. Can someone please provide me a sample code which will do batch insert or updates?? I have gone through the sample examples but it inserts only one record. I am not sure how to use querymore ,batchsize , queryoptions etc

My source is SQL server database.

Please help !!

 

 

 

SuperfellSuperfell
sforce.Account a1 = new sforce.Account();
a1.Name = "Account 1";
sforce.Account a2 = new sforce.Account();
a2.Name = "Account 2";
sforce.SObject [] objs = new sforce.SObject [] { a1, a2 };

sforce.SaveResult [] sr = binding.create(objs);
foreach (sforce.SaveResult s in sr)
{
if (s.sucess)
{
Console.WriteLine("new Id {0}", s.id);
}
else
{
Console.WriteLine("failed with error {0} {1}" s.errors[0].statusCode, s.errors[0].message);
}
}


update is the same except you call update instead of create.
ppatppat
Thank You Simon.
JeffGressJeffGress

Simon,

  Thanks for the great code.  Is there a way to do this where I don't have to name things A1, A2, etc?  What I would essentially like to do is run a query, take the results of the query and set a custom date field so that I don't query this again.  Not knowing how many records I am going to pull makes it both difficult and cumbersome to create a1,a2.etc.  Also I assume that after the query that gets every record I should only be doing the update once.  Can you help me with this?  My C# is rusty.  It seems like it should be pretty straight-forward.  Then again . . . :)

 

   Thanks,

 

     Jeff