1

Hi i am trying to write script for display list of records from wrapper class.

 @remoteaction
    public static wrappercls getaccounts(){
        string account = 'select id,name,accountnumber from account';
        listacc = database.query(account);
        count = listacc.size();
        system.debug('#####'+count);
        wrappercls wra = new wrappercls(count,listacc);
        return wra;
    }

    public class wrappercls{
        public integer count11;
        public list<account> account;

        public wrappercls(integer count11,list<account> account){
            this.count11 = count11;
            this.account = account;
        }
    } 

This class returns list of account records and record count parameter.Need to display these records in page.Is it possible if possible Please help me on this..

Script

<script>
  function getallaccounts(){
    exremote.getaccounts(
        function(result,event){
            if(event.status){

            }
            else {

            }
       },{escape:true}
    );
}
</script>

Thanks in Advance...

0

1 Answer 1

0

You already have the response in your result variable. Now it's up to you and your creativity how you're going to display the records on the page. You will need to write some JavaScript though. Here is a starting point and one way of creating a table dynamically and shoving it inside an existing DIV on your page:

<div id="accountList" />

<script>
  function getallaccounts(){
    exremote.getaccounts(
        function(result,event){
            if(event.status){
                var html = '<table>';

                for (var i = 0; i < result.count11; i++)
                {
                    html += '<tr>';
                    html += '<td>' + result.account[i].Id + '</td>';
                    html += '<td>' + result.account[i].name + '</td>';
                    html += '<td>' + result.account[i].accountnumber + '</td>';
                    html += '</tr>';
                }

                html += '</table>';
                document.getElementById('accountList').innerHTML = html;
            }
            else {

            }
       },{escape:true}
    );
}
</script>
0

You must log in to answer this question.