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
VNVN 

How to enhance the size of an API create call?

Hi We have a requirement where we are fetching records from Oracle database and populating it to salesforce system. we are using API create call for this using batching. API create call has a maximum limit of records that it can process. How can we enhance the size for batching of records for API calls? Please help. Thanks Priya
DevAngelDevAngel
The max number of records for a create or update is 200 per method invocation.  This is not modifiable.


Cheers
RickyGRickyG
VN -

You can move more than 200 records from an Oracle database into a Force.com object with the command line version of Data Loader.  I'm not sure if you could use this to address the size of your import, based on the particulars of your requirement, but you will not be limited by the API limitation.

Hope this helps.

VNVN
Hi Rick Thanks for your response. Can you please explain how exactly we can do it? May be with a sample code. Thanks in advance Priya
RickyGRickyG
VN -

This article details how to use Data Loader from the command line.  The Data Loader documentation includes descriptions of the configuration files needed to run Data Loader from the command line to access relational databases. 

Hope this gives you enough information to create an appropriate solution for you needs.
pmorellipmorelli
just as an fyi, the data loader does respect the 200 insert limit, it just chunks internally, inserts in sets of 200...
SuperfellSuperfell
The Force.com cookbook includes some example code of a batch wrapper for create/update, that automatically chunks large batches into small API call batches.
The other common pattern is to use an accumulator pattern. (this works better when you have an in-determinant and potentially very large number of source rows)
VNVN

Hi Simon,

Thanks for your response. Iam following the salesforce_platform_cookbook. There is a sample code for batching of records for API calls in page 200.when i paste the code in my program its giving me errors.

This is the sample code iam using.

 

public SaveResult[] create(SObject[] records, int batchSize)

throws InvalidSObjectFault, UnexpectedErrorFault,

InvalidIdFault, RemoteException,

ServiceException {

if (batchSize > 200 || batchSize < 1)

throw new IllegalArgumentException(

"batchSize must be between 1 and 200");

return batch(records, batchSize, new CreateBatcher());

}

Iam getting syntax error on the first two lines and on the last line error is CreateBatcher cannot be resolved to type.

Please help

Thanks

Priya

SuperfellSuperfell
You need the rest of the code from the sample.
VNVN
Hi Simon,
 
Thanks again...i pasted the whole code
 

public SaveResult[] create(SObject[] records, int batchSize)

throws InvalidSObjectFault, UnexpectedErrorFault,

InvalidIdFault, RemoteException,

ServiceException {

if (batchSize > 200 || batchSize < 1)

throw new IllegalArgumentException(

"batchSize must be between 1 and 200");

return batch(records, batchSize, new CreateBatcher());

}

private SaveResult[] batch(SObject[] records, int batchSize,

Batcher batchOperation)

throws UnexpectedErrorFault, InvalidIdFault,

LoginFault, RemoteException, ServiceException {

if (records.length <= batchSize) {

checkLogin();

return batchOperation.perform(records);

}

SaveResult[] saveResults = new SaveResult[records.length];

SObject[] thisBatch = null;

int pos = 0;

while (pos < records.length) {

int thisBatchSize = Math.min(batchSize,

records.length - pos);

if (thisBatch == null ||

thisBatch.length != thisBatchSize)

thisBatch = new SObject[thisBatchSize];

System.arraycopy(records, pos, thisBatch, 0,

thisBatchSize);

SaveResult [] batchResults = batch(thisBatch,

thisBatchSize,

batchOperation);

System.arraycopy(batchResults, 0, saveResults,

pos, thisBatchSize);

pos += thisBatchSize;

}

return saveResults;

}

private abstract class Batcher {

abstract SaveResult[] perform(SObject [] records)

throws UnexpectedErrorFault, InvalidIdFault,

LoginFault, RemoteException,

ServiceException;

}

private class CreateBatcher extends Batcher {

SaveResult [] perform(SObject [] records)

throws UnexpectedErrorFault, InvalidIdFault,

LoginFault, RemoteException, ServiceException {

checkLogin();

return binding.create(records);

}

}

private class UpdateBatcher extends Batcher {

SaveResult [] perform(SObject [] records)

throws UnexpectedErrorFault, InvalidIdFault, LoginFault,

RemoteException, ServiceException {

checkLogin();

return binding.update(records);

}

}

 

Again getting the same error at those lines along with many other errors down the code.

Please help.

Thanks

Priya

 

VNVN

Hi All,

My code doesn't throw any syntax error now. But iam getting Null Pointer Exception.

This is piece of code.

if (batchSize > 210 || batchSize < 1)

throw new IllegalArgumentException(

"batchSize must be between 1 and 200");

return batch(records, batchSize, x.new CreateBatcher()); /// Exception raised @ this point

}

 

Please help.

Thanks in advance

Priya