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

Too many apex request exception

Do you know what "too many apex requests" exception mean? I'm getting this message randomly. Has it something to do with the Callouts Limit?

could you please show some insight of the code so that I can provide with you some help on that.


We have implemented several triggers in different objects. We also have an integration process (sometimes 4 instances of this process are running at the same time) that creates new records for these objects through the API (in packets of 200)  what makes fire the corresponding triggers in mass.

I would have to post here all my triggers because I don't get any information about which trigger is causing the exception and actually, I can't see why it is necessary.


I have the same problem.. I am using the API to insert/update data in Salesforce.


I am always using the same username and inserting records one by one though but I get those exception like TOO_MANY_APEX_REQUEST and UNABLE_TO_LOCK_ROW quite frequently. 


Did you manage to solve the problem?



UNABLE_TO_LOCK_ROW is a concurrency problem, something else is doing an update which is holding the lock, and your API request is also trying to get the lock (typically on the parent object, depends on what features you're using) and the API request gave up after so long trying to get the lock. are you doing lots of concurrent API updates?, do you have a skewed data model (a single account that's the parent to all the child data) ?

yes, I have a default account that is the parent of almost 70% of my contacts, but I am not doing any updates on this account, only updates on the contacts, leads and/or cases and tasks. I update the contact with the respective account based in another field, using a trigger for that, could it be that what is locking?


You said the API gave up after so long trying... each contact update shouldn't take so long.. how long is the API waiting?

We also have lots of Workflows on Contacts, do you think that is locking too? I think the workflows take some time more than 40 seconds, is it a normal behaviour?


Do you know something about TOO_MANY_APEX_REQUEST? It is also happening when a batch of cases are created in a short period of time (one by one)


Thanks  for your help!

Message Edited by lopezc on 02-19-2009 01:22 AM
an update on a child of the account locks the account, so you have massive contention on that one account row. You'll need to fix your data model/skew to address this.



Thanks for your help! Do you think that each contact should be linked to only one account? is it the normal thing to do?

What happen if I create a grand parent account that is the parent of all the accounts linked to the contacts? would it be locked too?

Hi, Still getting lots of "TOO_MANY_APEX_REQUEST" errors. Any ideas?
Salesforce has a limit on the number of concurrent apex requests. Only FOUR requests can be processed at a time and four more will be queued. Once you exeede 8 users making any kind of apex request you will see this error.

Where did you get it from? Is it said in any Salesforce document? I've just found in the Winter'10 Apex Language Reference document the following:


"A user can have up to five query cursors open at a time. If five cursors are opened when a client application, still logged in
as the same user, attempts open a new one, the oldest of the five cursors is released. "


Does it have anything to do with it?


8 users? I have a client application using the API to insert/update data in salesforce. the client application is using the same user to do all this work and the records are inserted one by one. There might be more than 10 threads inserting and updating data and logged in as the same user.


How do you think a client application using the API should work? we can't have only 4 threads since each one is used for diffrent functionalities. One is for sending emails, others to insert contacts and leads, other used for cases, etc...

Depends on the duration fo each request. If your requests are running in milli seconds most likely you wont notice any difference. We have heavy customization with some apex code that takes up to a couple of seconds and we got hit with it. We logged a ticket with Salesforce and they say the app servers are designed to terminate the 9th request and that we should move some of our code to asynch.
Nope. This particular limitation "too many apex requests" is not published anywhere. However it is described in 501 developer class.
I mean "too many apex requests" is described in the 501 training material.

So you mean that 8 apex requests are the limit (Even if they come from different users?). I can see this error in my application quite often. How I said, I am using the same user to insert/update data automatically through the API and the processes sometimes are taking up to 10 seconds to do insert only a single contact.

So your solution was using the @Future call?


thanks for your help.

Message Edited by lopezc on 11-02-2009 07:31 AM

What counts as an apex request? I mean, apex code in triggers, is it considered as apex requests? Or does it depend on whether the trigger is executed due to an user operation through the interface or an external service creating or updating a record?


I opened a case regarding this issue, but they told me that it was the same limit as the API request limit... what doesn't make sense for me.


Could you please copy the paragraph where this limit is explained?


Since we do not know how customer Apex Code will perform, we have to protect ourselves against a customer consuming too many resources. Hence we allow at most 4 active Apex Code requests per appserver per org. Additional requests are queued for up to 5 sceconds. If the usage does not go down by then the waiter gets the error.


Unfortunately, you cannot predict how many app servers will be servicing your requests. If you requests are all serviced by one app server, only 4 requests that require Apex Code will be processed concurrently. If you requests span 2 app servers, the number of concurrent Apex Code requests goes to 8. And so on.. We are working very hard to replace the per app-server limit with an instance wide organization limit.


If you do escalate the TooManyApexRequestsException to support, please provide them with the following information: 


1)      Are you running a multi-thread API integration process that triggers Apex Code? If so, how many threads are you running?

2)      How many concurrent user requests are triggering Apex Code?  eg 10 users triggering apex code/sec

3)      How long on average do the various triggers take to execute? Use the system log to get this information. 



NOTE: the concurrency limit does not apply to async Apex Code (either @future or Batch) as async execution allows to throttle requests according to load.  


gjs, any (unofficial, non-binding, covered under safe harbor, etc.) idea what the new limits would be?

Would they be based on the number of users per org by chance?