Skip to main content
added 1526 characters in body
Source Link
E.J. Wilburn
  • 3.8k
  • 29
  • 29
<!-- Set the session ID for the AJAX toolkit to use automatically -->
<script type="text/javascript">
    var __sfdcSessionId = '{!GETSESSIONID()}';
</script>
<!-- Include the AJAX Toolkit -->
<script  src="/soap/ajax/25.0/connection.js" type="text/javascript" javascript"></>script>
<script  src="/soap/ajax/25.0/apex.js" type="text/javascript" />></script>
<script  type="text/javascript">
    // Execute the Apex web service.
    sforce.apex.execute( '<namespace>/<class>',
        '<method name>',
        {ownerId: '<ownerId>'},
        {onSuccess: displayCount, onFailure: errorHandler, timeout: 300000 //timeout in ms}
        );
    
    function displayCount( result )
    {
        // Add your code here to update/display your count.
    }
    
    function errorHandler( error )
    {
        // Handle errors.
    }
</script>

Information on the webService annotation can be found here: http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_web_services_methods_considerations.htm#kanchor587

Here's a simpler method for querying the count directly via the AJAX Toolkit without relying on a webService method.

<apex:page >
<!-- Set the session ID for the AJAX toolkit to use automatically -->
<script type="text/javascript">
    var __sfdcSessionId = '{!GETSESSIONID()}';
</script>
<!-- Include the AJAX Toolkit -->
<script src="/soap/ajax/25.0/connection.js" type="text/javascript"></script>
<script src="/soap/ajax/25.0/apex.js" type="text/javascript"></script>
<!-- jQuery -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script type="text/javascript">
    $().ready( function() {
            queryCount();
        });

    function queryCount()
    {
        // Execute the Apex web service.
        sforce.connection.query(
            "SELECT Count() FROM Lead",
            {
                onSuccess: handleCount,
                onFailure: queryFailed, 
                timeout: 300000 // Set timeout to 5 minutes
            });
    }
    
    function handleCount( result )
    {
        // Add your code here to update/display your count.
        $( '#output' ).append( result.size );
        
    }

    function queryFailed( error )
    {
        // Handle errors.
        $( '#output' ).append( error );
    }
</script>
<div id="output">
</div>
</apex:page>
<!-- Set the session ID for the AJAX toolkit to use automatically -->
<script type="text/javascript">
    var __sfdcSessionId = '{!GETSESSIONID()}';
</script>
<!-- Include the AJAX Toolkit -->
<script  src="/soap/ajax/25.0/connection.js" type="text/javascript" />
<script  src="/soap/ajax/25.0/apex.js" type="text/javascript" />
<script  type="text/javascript">
    // Execute the Apex web service.
    sforce.apex.execute( '<namespace>/<class>',
        '<method name>',
        {ownerId: '<ownerId>'},
        {onSuccess: displayCount, onFailure: errorHandler, timeout: 300000 //timeout in ms}
        );
    
    function displayCount()
    {
        // Add your code here to update/display your count.
    }
    
    function errorHandler()
    {
        // Handle errors.
    }
</script>

Information on the webService annotation can be found here: http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_web_services_methods_considerations.htm#kanchor587

<!-- Set the session ID for the AJAX toolkit to use automatically -->
<script type="text/javascript">
    var __sfdcSessionId = '{!GETSESSIONID()}';
</script>
<!-- Include the AJAX Toolkit -->
<script  src="/soap/ajax/25.0/connection.js" type="text/javascript"></script>
<script  src="/soap/ajax/25.0/apex.js" type="text/javascript"/></script>
<script  type="text/javascript">
    // Execute the Apex web service.
    sforce.apex.execute( '<namespace>/<class>',
        '<method name>',
        {ownerId: '<ownerId>'},
        {onSuccess: displayCount, onFailure: errorHandler, timeout: 300000 //timeout in ms}
        );
    
    function displayCount( result )
    {
        // Add your code here to update/display your count.
    }
    
    function errorHandler( error )
    {
        // Handle errors.
    }
</script>

Information on the webService annotation can be found here: http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_web_services_methods_considerations.htm#kanchor587

Here's a simpler method for querying the count directly via the AJAX Toolkit without relying on a webService method.

<apex:page >
<!-- Set the session ID for the AJAX toolkit to use automatically -->
<script type="text/javascript">
    var __sfdcSessionId = '{!GETSESSIONID()}';
</script>
<!-- Include the AJAX Toolkit -->
<script src="/soap/ajax/25.0/connection.js" type="text/javascript"></script>
<script src="/soap/ajax/25.0/apex.js" type="text/javascript"></script>
<!-- jQuery -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script type="text/javascript">
    $().ready( function() {
            queryCount();
        });

    function queryCount()
    {
        // Execute the Apex web service.
        sforce.connection.query(
            "SELECT Count() FROM Lead",
            {
                onSuccess: handleCount,
                onFailure: queryFailed, 
                timeout: 300000 // Set timeout to 5 minutes
            });
    }
    
    function handleCount( result )
    {
        // Add your code here to update/display your count.
        $( '#output' ).append( result.size );
        
    }

    function queryFailed( error )
    {
        // Handle errors.
        $( '#output' ).append( error );
    }
</script>
<div id="output">
</div>
</apex:page>
added 1192 characters in body
Source Link
E.J. Wilburn
  • 3.8k
  • 29
  • 29

It sounds like your Apex method is taking longer than the JavaScript Remoting timeout, which is 30 seconds.

To my knowledge JavaScript Remoting still doesn't allow you to specify a custom timeout. I researched this pretty heavily back in January or so and that was the answer I received.

I do have an idea on the IdeaExchange to allow user customizable timeouts. Please take a moment and vote that idea up: https://sites.secure.force.com/success/ideaView?id=08730000000gLukAAE

My suggestion for fixing your issue in the meantime would be to switch to executing this method as a web service call and use the AJAX toolkit to call the web service in your VisualForce page.

Here's some example code to add to a VisualForce page to call an Apex web service with the AJAX Toolkit. You'll need to define your method with the webService annotation and it will need to be in a global class.

<!-- Set the session ID for the AJAX toolkit to use automatically -->
<script type="text/javascript">
    var __sfdcSessionId = '{!GETSESSIONID()}';
</script>
<!-- Include the AJAX Toolkit -->
<script  src="/soap/ajax/25.0/connection.js" type="text/javascript" />
<script  src="/soap/ajax/25.0/apex.js" type="text/javascript" />
<script  type="text/javascript">
    // Execute the Apex web service.
    sforce.apex.execute( '<namespace>/<class>',
        '<method name>',
        {ownerId: '<ownerId>'},
        {onSuccess: displayCount, onFailure: errorHandler, timeout: 300000 //timeout in ms}
        );
    
    function displayCount()
    {
        // Add your code here to update/display your count.
    }
    
    function errorHandler()
    {
        // Handle errors.
    }
</script>

Information on the webService annotation can be found here: http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_web_services_methods_considerations.htm#kanchor587

You might also consider creating a custom object to aggregate these totals on a nightly, hourly or semi-hourly basis by executing a scheduled Batch Apex job. You could then quickly query that table to display the requested data.

It sounds like your Apex method is taking longer than the JavaScript Remoting timeout, which is 30 seconds.

To my knowledge JavaScript Remoting still doesn't allow you to specify a custom timeout. I researched this pretty heavily back in January or so and that was the answer I received.

I do have an idea on the IdeaExchange to allow user customizable timeouts. Please take a moment and vote that idea up: https://sites.secure.force.com/success/ideaView?id=08730000000gLukAAE

My suggestion for fixing your issue in the meantime would be to switch to executing this method as a web service call and use the AJAX toolkit to call the web service in your VisualForce page.

Here's some example code to add to a VisualForce page to call an Apex web service with the AJAX Toolkit. You'll need to define your method with the webService annotation and it will need to be in a global class.

<!-- Set the session ID for the AJAX toolkit to use automatically -->
<script type="text/javascript">
    var __sfdcSessionId = '{!GETSESSIONID()}';
</script>
<!-- Include the AJAX Toolkit -->
<script  src="/soap/ajax/25.0/connection.js" type="text/javascript" />
<script  src="/soap/ajax/25.0/apex.js" type="text/javascript" />
<script  type="text/javascript">
    // Execute the Apex web service.
    sforce.apex.execute( '<namespace>/<class>',
        '<method name>',
        {ownerId: '<ownerId>'},
        {onSuccess: displayCount, onFailure: errorHandler, timeout: 300000 //timeout in ms}
        );
    
    function displayCount()
    {
        // Add your code here to update/display your count.
    }
    
    function errorHandler()
    {
        // Handle errors.
    }
</script>

It sounds like your Apex method is taking longer than the JavaScript Remoting timeout, which is 30 seconds.

To my knowledge JavaScript Remoting still doesn't allow you to specify a custom timeout. I researched this pretty heavily back in January or so and that was the answer I received.

I do have an idea on the IdeaExchange to allow user customizable timeouts. Please take a moment and vote that idea up: https://sites.secure.force.com/success/ideaView?id=08730000000gLukAAE

My suggestion for fixing your issue in the meantime would be to switch to executing this method as a web service call and use the AJAX toolkit to call the web service in your VisualForce page.

Here's some example code to add to a VisualForce page to call an Apex web service with the AJAX Toolkit. You'll need to define your method with the webService annotation and it will need to be in a global class.

<!-- Set the session ID for the AJAX toolkit to use automatically -->
<script type="text/javascript">
    var __sfdcSessionId = '{!GETSESSIONID()}';
</script>
<!-- Include the AJAX Toolkit -->
<script  src="/soap/ajax/25.0/connection.js" type="text/javascript" />
<script  src="/soap/ajax/25.0/apex.js" type="text/javascript" />
<script  type="text/javascript">
    // Execute the Apex web service.
    sforce.apex.execute( '<namespace>/<class>',
        '<method name>',
        {ownerId: '<ownerId>'},
        {onSuccess: displayCount, onFailure: errorHandler, timeout: 300000 //timeout in ms}
        );
    
    function displayCount()
    {
        // Add your code here to update/display your count.
    }
    
    function errorHandler()
    {
        // Handle errors.
    }
</script>

Information on the webService annotation can be found here: http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_web_services_methods_considerations.htm#kanchor587

You might also consider creating a custom object to aggregate these totals on a nightly, hourly or semi-hourly basis by executing a scheduled Batch Apex job. You could then quickly query that table to display the requested data.

added 1192 characters in body
Source Link
E.J. Wilburn
  • 3.8k
  • 29
  • 29

It sounds like your Apex method is taking longer than the JavaScript Remoting timeout, which is 30 seconds.

To my knowledge JavaScript Remoting still doesn't allow you to specify a custom timeout. I researched this pretty heavily back in January or so and that was the answer I received.

I do have an idea on the IdeaExchange to allow user customizable timeouts. Please take a moment and vote that idea up: https://sites.secure.force.com/success/ideaView?id=08730000000gLukAAE

My suggestion for fixing your issue in the meantime would be to switch to executing this method as a web service call and use the AJAX toolkit to call the web service in your VisualForce page.

Here's some example code to add to a VisualForce page to call an Apex web service with the AJAX Toolkit. You'll need to define your method with the webService annotation and it will need to be in a global class.

<!-- Set the session ID for the AJAX toolkit to use automatically -->
<script type="text/javascript">
    var __sfdcSessionId = '{!GETSESSIONID()}';
</script>
<!-- Include the AJAX Toolkit -->
<script  src="/soap/ajax/25.0/connection.js" type="text/javascript" />
<script  src="/soap/ajax/25.0/apex.js" type="text/javascript" />
<script  type="text/javascript">
    // Execute the Apex web service.
    sforce.apex.execute( '<namespace>/<class>',
        '<method name>',
        {ownerId: '<ownerId>'},
        {onSuccess: displayCount, onFailure: errorHandler, timeout: 300000 //timeout in ms}
        );
    
    function displayCount()
    {
        // Add your code here to update/display your count.
    }
    
    function errorHandler()
    {
        // Handle errors.
    }
</script>

It sounds like your Apex method is taking longer than the JavaScript Remoting timeout, which is 30 seconds.

To my knowledge JavaScript Remoting still doesn't allow you to specify a custom timeout. I researched this pretty heavily back in January or so and that was the answer I received.

I do have an idea on the IdeaExchange to allow user customizable timeouts. Please take a moment and vote that idea up: https://sites.secure.force.com/success/ideaView?id=08730000000gLukAAE

It sounds like your Apex method is taking longer than the JavaScript Remoting timeout, which is 30 seconds.

To my knowledge JavaScript Remoting still doesn't allow you to specify a custom timeout. I researched this pretty heavily back in January or so and that was the answer I received.

I do have an idea on the IdeaExchange to allow user customizable timeouts. Please take a moment and vote that idea up: https://sites.secure.force.com/success/ideaView?id=08730000000gLukAAE

My suggestion for fixing your issue in the meantime would be to switch to executing this method as a web service call and use the AJAX toolkit to call the web service in your VisualForce page.

Here's some example code to add to a VisualForce page to call an Apex web service with the AJAX Toolkit. You'll need to define your method with the webService annotation and it will need to be in a global class.

<!-- Set the session ID for the AJAX toolkit to use automatically -->
<script type="text/javascript">
    var __sfdcSessionId = '{!GETSESSIONID()}';
</script>
<!-- Include the AJAX Toolkit -->
<script  src="/soap/ajax/25.0/connection.js" type="text/javascript" />
<script  src="/soap/ajax/25.0/apex.js" type="text/javascript" />
<script  type="text/javascript">
    // Execute the Apex web service.
    sforce.apex.execute( '<namespace>/<class>',
        '<method name>',
        {ownerId: '<ownerId>'},
        {onSuccess: displayCount, onFailure: errorHandler, timeout: 300000 //timeout in ms}
        );
    
    function displayCount()
    {
        // Add your code here to update/display your count.
    }
    
    function errorHandler()
    {
        // Handle errors.
    }
</script>
Source Link
E.J. Wilburn
  • 3.8k
  • 29
  • 29
Loading