On a visualforce page that I created to upload documents, I tried to upload 500 documents at once. But it always exceeds the CPU time limit. Is there a way to invoke controller method Asynchronously for 500 times? Or any suggestion on how to bypass the CPU time limit? Thank you.

  • Any specific reason not to use DataLoader?
    – Saroj Bera
    Feb 10 '17 at 3:37

You can use Javascript Remoting to split up your calls to the server. Javascript Remoting has a callback function which you could use for subsequent calls to the server:

More details on JS Remoting here: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_js_remoting.htm

Here's an example of what it would look like with the callback handler (taken from here: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_js_remoting_example.htm):

<script type="text/javascript">
function getRemoteAccount() {
    var accountName = document.getElementById('acctSearch').value;

        function(result, event){
            if (event.status) {
                // Get DOM IDs for HTML and Visualforce elements like this
                document.getElementById('remoteAcctId').innerHTML = result.Id
                    ).innerHTML = result.NumberOfEmployees;
            } else if (event.type === 'exception') {
                document.getElementById("responseErrors").innerHTML = 
                    event.message + "<br/>\n<pre>" + event.where + "</pre>";
            } else {
                document.getElementById("responseErrors").innerHTML = event.message;
        {escape: true}

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.