You need to sign in to do that
Don't have an account?
alivepjc
Creating objects in batches C#
Hi,
I've been searching the forums for creating objects in batches of 200 but I can't find any examples (C#). the sample code to download doesn't have an example of batch creation. To create opportunities for example, I do this:
sforce.Opportunity newOp = new sforce.Opportunity();
// populate newOp
newOp.AccountId = acct_id;
newOp.StageName = "ClosedWon"
newOp.Name = "John";
sforce.sObject[] records = new sforce.sObject[] {newOp};
sforce.SaveResult[] saveResults = binding.create(records);
this is OK if I need to create a few, but if I need to create thousands of them, it is not OK. I know this is simple question, but I can't find the answer.. I'd like to follow the best practices..
thank you!
If you set an array of size 2 for the create call, then 2 records will be created per call.
If you create an array containing 200 SObjects, and pass that array of 200 to the create call, then 200 records will be created with that call.
The upper limit is 200.
Something like this?
sforce.sObject[] records = new sforce.sObject[10];
for (int i=0; i< 10; i++)
{
sforce.Opportunity newOp = new sforce.Opportunity();
// populate newOp
records[i] = newOp;
}
sforce.SaveResult[] saveResults = binding.create(records);