-2

How to display all records which are available in custom object by using jquery plugin(Same as pagination in visualforce page).

1

The easiest way I've found is to make use of the AJAX Toolkit and the sforce.connection.query method (remember to change the actual query to what you're after).

<script type="text/javascript">
    var __sfdcSessionId = '{!GETSESSIONID()}';
</script>

<script src="../../soap/ajax/30.0/connection.js" type="text/javascript"></script>

<script type="text/javascript">
    function doQuery
    {
        sforce.connection.query
        (
            "Select Id, Name, Industry From Account order by Industry",
            {
                onSuccess: onSuccess,
                onFailure: onFailure,
                source: { //state that you need when the callback is called }
            }
        );
    }

    function onSuccess(result, source) 
    {
        var records = result.getArray("records");

        for (var i = 0; i < records.length; i++) 
        {
            var record = records[i];
            log(record.Name + " -- " + record.Id);
        }
    }    

    function onFailure(error, source) 
    {
        // Handle failure
    }
</script>

Another recommended route is to use Javascript Remoting for Visualforce. One of the advantages of JS remoting over the AJAX Toolkit is the ability to setup and control your logic of what is returned in apex. Here is a stubbed out example:

function getAttachments() {

    Visualforce.remoting.Manager.invokeAction(
        '{!$RemoteAction.MyController.findAttachments}', 
        [ARGUMENTS], 
        function(result, event){
            if (event.status) {
                //success, do what you need to do with jQuery
            } else {
                //handle errors
            }
        }, 
        {escape: true}
    );
}

You would also need a corresponding controller and @RemoteAction method

@RemoteAction
global static List<Attachment> findAttachments() { ... }
  • Thanks for the quick response..But i need to get the records through jquery only – Sfdc learner Jun 20 '16 at 7:00
  • Can anyone give me the sample code..So that it will be helpful for me.. – Sfdc learner Jun 20 '16 at 9:28
  • ohotech.com/2015/05/… is the sample code for resolving the above question.. – Sfdc learner Jun 20 '16 at 10:49

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