1

I have an Apex REST class with a POST method:

@HttpPost
global static List<Id> doPost(List<TaskWrapper> tasks) {
    List<Task> tasksToInsert = new List<Task>();

    for (TaskWrapper task : tasks) {
        tasksToInsert.add(task.getTask());
    }

    insert tasksToInsert;

    Map<Id, Task> taskMap = new Map<Id, Task>(tasksToInsert);
    return new List<Id>(taskMap.keySet());
}

Request's body looks like this:

{
    "tasks": [
        {
            "subject": "Edna's task",
            "priority": "High",
            "status": "Not Started",
            "externalId": "efrank"
        }, {
            "subject": "Andy's task",
            "priority": "Low",
            "status": "In Progress",
            "externalId": "ayoung"
        }
    ]
}

Question: Is there any documented limit of maximum number of records which can be passed in JSON file through an Apex REST API method?

The only thing I found is Static Apex Limits section in Execution Governors and Limits:

Maximum size of callout request or response (HTTP request or Web services call): 6 MB for synchronous Apex or 12 MB for asynchronous Apex

But I'm not sure if this is the only limitation. If amount of fields passed in the request is small enough, I can send more than 60 000 records - what, in my opinion, is quite a lot.

  • how did you figure out 60k records? – AtulRajguru9 Jun 26 '18 at 10:16
  • @AtulRajguru9 File with 100 records and with every having 2 fields : 8,4kB -> 1 record = 0,084 kB; 6144 kB / 0,084 kB ~= 73k records. Added a little margin, that's why I said "more than" :> – notmyf4ulty Jun 26 '18 at 10:25
1

Even if you consider best case scenario with following points: 1) you have no trigger in place, no workflows, no additional processing 2) you are just dumping data in target object - no query

Then also you will not be able to insert more than 10k records. Not just in APi but in UI or any other synchronous process.

whatever way you try in synchronous execution we can not insert more than 10k rows.

Here is code to prove my point.

Map<Integer,list<Task>> mapOfList = new Map<Integer,list<Task>>();
List<Task> tasklist = new List<Task>();
For(integer i =0; i<100;i++){
    For(integer j =0; j<9999; j++){ // 10k tasks
        Task t = New Task(Subject = 'Test task', priority = 'Low', status = 'In Progress' );                
        tasklist.add(t);
    }    
    mapOfList.put(i,tasklist);
}

For(Integer i : mapOfList.keyset() ){
    insert mapOfList.get(i);
    System.debug('insert ' +  i);
}

System.debug('Final Heap Size: ' +  Limits.getHeapSize());
System.debug('Final Cpu Time(): ' +  Limits.getCpuTime());

Note following things:
1) We can hold 10k * 100 = 1000K rows in HEAP using map of list and apex wont complain
2) There is not any CUP intensive operation so CPU time limit wont come in picture (DB time is calculated separably)
3) There are no SQL queries
4) Total # DML statements(insert in out case) are less than 150

Ref: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_gov_limits.htm

0

You are right ...you can send as many records as can accommodated in 6mb. So if you are sending only few fields of task then you can send larger set of records but as you will increase the number of fields, size will get decreased to maintain 6mb limit.

Also, significantly note that still salesforce governor limit would be there while inserting/processing the records like:

1). You can not insert more than 10000 rows of records in a single call.
2). You wont be able to query more than 50K rows in your method
3). You wont be able to do more than 100 SOQL in single context.
4). Heap Size/collection limit.
5). Too many CPU time limit.

If you have large chunk of data ,then call this method in multiple batches .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.