0

to all. I am trying to provide the refresh button on my page it's have only done on "Refresh the current result of the page and showing the same result".

But I have the idea only for that page and I don't know to how to implement here I am very struggle to write the function for the refresh function for that in my apex class.so can any one help me to done this function.

For your help My controller class,

public class StandardPaginationSorting {

    // Variables required for Sorting.
    public String soql {get;set;}
    public List <Account> CandidateList1 = New List <Account>();
    public String soqlsort {get;set;}
    public List <Account> CandidateList2 = New List <Account>();
    public List<Account> acc {get; set;}

                // List used in to display the table in VF page.
                public List<Account> getCandidateList() {
                    // Passing the values of list to VF page.
                    return con.getRecords();
                    //all();
                }

                // instantiate the StandardSetController from a query locator
                public StandardPaginationSorting(ApexPages.StandardController controller){
                 con.getRecords();
                 all();
                }
                public ApexPages.StandardSetController con {
                    get {
                                                if(con == null) {
                                                                // String Query to have a list of cases for a respective End-user.
                                                                soql = 'SELECT Name, Website, BillingCountry, Phone, Type, Owner.Name FROM Account';

                                                                // Passing the String array to a list with Selected field sorting.
                                                                CandidateList1 = Database.query(soql + ' order by ' + sortField + ' ' + sortDir ); 

                                                                // setting values of List in StandardSetController.
                                                                con = new ApexPages.StandardSetController(CandidateList1);

                                                                // sets the number of records in each page set
                                                                con.setPageSize(10);
                                                }
                                                return con;
        }
        set;
    }

    // indicates whether there are more records after the current page set.
    public Boolean hasNext {
        get {
            return con.getHasNext();
        }
        set;
    }

    // indicates whether there are more records before the current page set.
    public Boolean hasPrevious {
        get {
            return con.getHasPrevious();
        }
        set;
    }

    // returns the page number of the current page set
    public Integer pageNumber {
        get {
            return con.getPageNumber();
        }
        set;
    }

    // returns the first page of records
    public void first() {
        con.first();
    }

    // returns the last page of records
    public void last() {
        con.last();
    }

    // returns the previous page of records
    public void previous() {
        con.previous();
    }

    // returns the next page of records
    public void next() {
        con.next();
    }

    // returns the PageReference of the original page, if known, or the home page.
    public void cancel() {
        con.cancel();
    }

    // Method for Constructor is used for Test Class.
    public StandardPaginationSorting(){ 
        //all();     
    }

   //Toggles the sorting of query from asc<-->desc
    public void toggleSort() {
        // simply toggle the direction
        sortDir = sortDir.equals('asc') ? 'desc' : 'asc';

                                // run the query again for sorting other columns
                                soqlsort = 'SELECT Name, Phone, BillingCountry, Website, Owner.Name, Type FROM Account'; 

                                // Adding String array to a List array
                                CandidateList2 = Database.query(soqlsort + ' order by ' + sortField + ' ' + sortDir ); 

                                // Adding Caselist to Standard Pagination controller variable
                                con = new ApexPages.StandardSetController(CandidateList2);

                                // Set Page Size to 10
                                con.setPageSize(10);

    }

    // the current sort direction. defaults to asc
    public String sortDir {
        // To set a Direction either in ascending order or descending order.
                                get  { if (sortDir == null) {  sortDir = 'asc';} return sortDir;}
        set;
    }

    // the current field to sort by. defaults to last name
    public String sortField {
        // To set a Field for sorting.
                                get  { if (sortField == null) {sortField = 'Name'; } return sortField;  }
        set;
    } 
    //the alpha bar navigation filter

    String A;
    public PageReference aaa() {
        A = 'a';
        acc.clear();
        String qry = 'SELECT  Name, Phone, Type, Owner.Name, BillingCountry, Website FROM Account WHERE Name LIKE \''+A+'%\' ORDER BY Name';
        acc= Database.query(qry);
        con = new ApexPages.StandardSetController(acc);
        return null;
    }

    String B;
    public PageReference bbb() {
        B = 'b';
        acc.clear();
        String qry = 'SELECT  Name, Phone, Type, Owner.Name, BillingCountry, Website FROM Account WHERE Name LIKE \''+B+'%\' ORDER BY Name';
        acc= Database.query(qry);
        con = new ApexPages.StandardSetController(acc);
        return null;
    }

    String C;
    public PageReference ccc() {
        C = 'c';
        acc.clear();
        String qry = 'SELECT  Name, Phone, Type, Owner.Name, BillingCountry, Website FROM Account WHERE Name LIKE \''+C+'%\' ORDER BY Name';
        acc= Database.query(qry);
        con = new ApexPages.StandardSetController(acc);
        return null;
    }

    String D;
    public PageReference ddd() {
        D = 'd';
        acc.clear();
        String qry = 'SELECT  Name, Phone, Type, Owner.Name, BillingCountry, Website FROM Account WHERE Name LIKE \''+D+'%\' ORDER BY Name';
        acc= Database.query(qry);
        con = new ApexPages.StandardSetController(acc);
        return null;
    }

    String E;
    public PageReference eee() {
        E = 'e';
        acc.clear();
        String qry = 'SELECT  Name, Phone, Type, Owner.Name, BillingCountry, Website FROM Account WHERE Name LIKE \''+E+'%\' ORDER BY Name';
        acc= Database.query(qry);
        con = new ApexPages.StandardSetController(acc);
        return null;
    }

    String F;
    public PageReference fff() {
    F = 'f';
    acc.clear();
    String qry = 'SELECT  Name, Phone, Type, Owner.Name, BillingCountry FROM Account WHERE Name LIKE \''+F+'%\' ORDER BY Name';
    acc= Database.query(qry);
    con = new ApexPages.StandardSetController(acc);
        return null;
    }

     String G;
    public PageReference ggg() {
        G = 'g';
        acc.clear();
        String qry = 'SELECT  Name, Phone, Type, Owner.Name, BillingCountry, Website FROM Account WHERE Name LIKE \''+G+'%\' ORDER BY Name';
        acc= Database.query(qry);
        con = new ApexPages.StandardSetController(acc);
        return null;
    }

    String H;
    public PageReference hhh() {
     H = 'h';
    acc.clear();
    String qry = 'SELECT  Name, Phone, Type, Owner.Name, BillingCountry, Website FROM Account WHERE Name LIKE \''+H+'%\' ORDER BY Name';
    acc= Database.query(qry);
    con = new ApexPages.StandardSetController(acc);
        return Null;
    }

    String I;
    public PageReference iii() {
     I = 'i';
    acc.clear();
    String qry = 'SELECT  Name, Phone, Type, Owner.Name, BillingCountry, Website FROM Account WHERE Name LIKE \''+I+'%\' ORDER BY Name';
    acc= Database.query(qry);
    con = new ApexPages.StandardSetController(acc);
        return Null;
    }

    String J;
    public PageReference jjj() {
     J = 'j';
    acc.clear();
    String qry = 'SELECT  Name, Phone, Type, Owner.Name, BillingCountry, Website FROM Account WHERE Name LIKE \''+J+'%\' ORDER BY Name';
    acc= Database.query(qry);
    con = new ApexPages.StandardSetController(acc);
        return Null;
    }

    String K;
    public PageReference kkk() {
     K = 'k';
    acc.clear();
    String qry = 'SELECT  Name, Phone, Type, Owner.Name, BillingCountry, Website FROM Account WHERE Name LIKE \''+K+'%\' ORDER BY Name';
    acc= Database.query(qry);
    con = new ApexPages.StandardSetController(acc);
        return Null;
    }

    String L;
    public PageReference lll() {
     L = 'l';
    acc.clear();
    String qry = 'SELECT  Name, Phone, Type, Owner.Name, BillingCountry, Website FROM Account WHERE Name LIKE \''+L+'%\' ORDER BY Name';
    acc= Database.query(qry);
    con = new ApexPages.StandardSetController(acc);
        return Null;
    }

    String M;
    public PageReference mmm() {
    M = 'm';
    acc.clear();
    String qry = 'SELECT  Name, Phone, Type, Owner.Name, BillingCountry, Website FROM Account WHERE Name LIKE \''+M+'%\' ORDER BY Name';
    acc= Database.query(qry);
    con = new ApexPages.StandardSetController(acc);
        return null;
    }

    String N;
    public PageReference nnn() {
     N = 'n';
    acc.clear();
    String qry = 'SELECT  Name, Phone, Type, Owner.Name, BillingCountry, Website FROM Account WHERE Name LIKE \''+N+'%\' ORDER BY Name';
    acc= Database.query(qry);
    con = new ApexPages.StandardSetController(acc);
        return Null;
    }

    String O;
    public PageReference ooo() {
    O = 'o';
    acc.clear();
    String qry = 'SELECT  Name, Phone, Type, Owner.Name, BillingCountry, Website FROM Account WHERE Name LIKE \''+O+'%\' ORDER BY Name';
    acc= Database.query(qry);
    con = new ApexPages.StandardSetController(acc);
        return null;
    }

    String P;
    public PageReference ppp() {
     P = 'p';
    acc.clear();
    String qry = 'SELECT  Name, Phone, Type, Owner.Name, BillingCountry, Website FROM Account WHERE Name LIKE \''+P+'%\' ORDER BY Name';
    acc= Database.query(qry);
    con = new ApexPages.StandardSetController(acc);
        return Null;
    }

    String Q;
    public PageReference qqq() {
     Q = 'q';
    acc.clear();
    String qry = 'SELECT  Name, Phone, Type, Owner.Name, BillingCountry, Website FROM Account WHERE Name LIKE \''+Q+'%\' ORDER BY Name';
    acc= Database.query(qry);
    con = new ApexPages.StandardSetController(acc);
        return Null;
    }

    String R;
    public PageReference rrr() {
     R = 'r';
    acc.clear();
    String qry = 'SELECT  Name, Phone, Type, Owner.Name, BillingCountry, Website FROM Account WHERE Name LIKE \''+R+'%\' ORDER BY Name';
    acc= Database.query(qry);
    con = new ApexPages.StandardSetController(acc);
        return Null;
    }

    String S;
    public PageReference sss() {
     S = 's';
    acc.clear();
    String qry = 'SELECT  Name, Phone, Type, Owner.Name, BillingCountry, Website FROM Account WHERE Name LIKE \''+S+'%\' ORDER BY Name';
    acc= Database.query(qry);
    con = new ApexPages.StandardSetController(acc);
        return Null;
    }

    String T;
    public PageReference ttt() {
     T = 't';
    acc.clear();
    String qry = 'SELECT  Name, Phone, Type, Owner.Name, BillingCountry, Website FROM Account WHERE Name LIKE \''+T+'%\' ORDER BY Name';
    acc= Database.query(qry);
    con = new ApexPages.StandardSetController(acc);
        return Null;
    }

    String U;
    public PageReference uuu() {
     U = 'u';
    acc.clear();
    String qry = 'SELECT  Name, Phone, Type, Owner.Name, BillingCountry, Website FROM Account WHERE Name LIKE \''+U+'%\' ORDER BY Name';
    acc= Database.query(qry);
    con = new ApexPages.StandardSetController(acc);
        return Null;
    }

    String V;
    public PageReference vvv() {
     V = 'v';
    acc.clear();
    String qry = 'SELECT  Name, Phone, Type, Owner.Name, BillingCountry, Website FROM Account WHERE Name LIKE \''+V+'%\' ORDER BY Name';
    acc= Database.query(qry);
    con = new ApexPages.StandardSetController(acc);
        return Null;
    }

    String W;
    public PageReference www() {
     W = 'w';
    acc.clear();
    String qry = 'SELECT  Name, Phone, Type, Owner.Name, BillingCountry, Website FROM Account WHERE Name LIKE \''+W+'%\' ORDER BY Name';
    acc= Database.query(qry);
    con = new ApexPages.StandardSetController(acc);
        return Null;
    }

    String X;
    public PageReference xxx() {
     X = 'x';
    acc.clear();
    String qry = 'SELECT  Name, Phone, Type, Owner.Name, BillingCountry, Website FROM Account WHERE Name LIKE \''+X+'%\' ORDER BY Name';
    acc= Database.query(qry);
    con = new ApexPages.StandardSetController(acc);
        return Null;
    }

    String Y;
    public PageReference yyy() {
     Y = 'y';
    acc.clear();
    String qry = 'SELECT  Name, Phone, Type, Owner.Name, BillingCountry, Website FROM Account WHERE Name LIKE \''+Y+'%\' ORDER BY Name';
    acc= Database.query(qry);
    con = new ApexPages.StandardSetController(acc);
        return Null;
    }

    String Z;
    public PageReference zzz() {
     Z = 'z';
    acc.clear();
    String qry = 'SELECT  Name, Phone, Type, Owner.Name, BillingCountry, Website FROM Account WHERE Name LIKE \''+Z+'%\' ORDER BY Name';
    acc= Database.query(qry);
    con = new ApexPages.StandardSetController(acc);
        return Null;
    }

    public void all() {
        acc = [SELECT Name, Phone, Type, Owner.Name, BillingCountry, Website FROM Account];
        con = new ApexPages.StandardSetController(acc);
        con.setpagesize(10);
    }
    public PageReference Refresh(){

        return Null;
    }


}

here I already done the pagination and sorting and alpha bar navigation in my class.

My visual Page is,

<apex:page standardController="Account" extensions="StandardPaginationSorting" showHeader="false" sidebar="false" applyHtmlTag="true">


    <!-- CSS added to display alternate row colors and Center align Text in PageblockTable -->
    <!--<style type="text/css">
        .oddrow{background-color: #00FFFF; } 
        .evenrow{background-color: #7FFFD4; } 
        .textalign{text-align:center; } 
    </style>--->

    <apex:form id="form">
        <!-- Tabstyle attribute is used to assign the color scheme to the pageblock.Here Candidate Object color scheme is used for the pageblock-->

        <apex:pageBlock id="pgblock" tabStyle="Account">
            <!--<apex:pageBlockSection title="Candidate Details -  Page #{!pageNumber}" columns="1" collapsible="false">-->   
                <!-- Rowclasses attribute is used to define different CSS classes for different rows. 
                     Rules attribute is used: borders drawn between cells in the page block table.
                     Title attribute will be used as a help text when a user hovers mouse over the Page Block table.
                     Styleclass, HeaderClass attributes are used to Center align Table Text in Page Block table --->
            <!--refresh the page and showing the same result of this refresh button---> 
            <apex:pageBlockButtons>
                <apex:commandButton onclick="{!refresh()}"/>
            </apex:pageBlockButtons> 
            <right>
            <apex:toolbar id="toolbar" height="10" style="background-color:White;background-image:none;">
            <apex:toolbarGroup itemSeparator="line">
                <apex:commandLink value="A" Action="{!aaa}"/>
                <apex:commandLink value="B" Action="{!bbb}"/>
                <apex:commandLink value="C" Action="{!ccc}"/>
                <apex:commandLink value="D" Action="{!ddd}"/>
                <apex:commandLink value="E" Action="{!eee}"/>
                <apex:commandLink value="F" Action="{!fff}"/>
                <apex:commandLink value="G" Action="{!ggg}"/>
                <apex:commandLink value="H" Action="{!hhh}"/>
                <apex:commandLink value="I" Action="{!iii}"/>
                <apex:commandLink value="J" Action="{!jjj}"/>
                <apex:commandLink value="K" Action="{!kkk}"/>
                <apex:commandLink value="L" Action="{!lll}"/>
                <apex:commandLink value="M" Action="{!mmm}"/>
                <apex:commandLink value="N" Action="{!nnn}"/>
                <apex:commandLink value="O" Action="{!ooo}"/>
                <apex:commandLink value="P" Action="{!ppp}"/>
                <apex:commandLink value="Q" Action="{!qqq}"/>
                <apex:commandLink value="R" Action="{!rrr}"/>
                <apex:commandLink value="S" Action="{!sss}"/>
                <apex:commandLink value="T" Action="{!ttt}"/>
                <apex:commandLink value="U" Action="{!uuu}"/>
                <apex:commandLink value="V" Action="{!vvv}"/>
                <apex:commandLink value="W" Action="{!www}"/>
                <apex:commandLink value="X" Action="{!xxx}"/>
                <apex:commandLink value="Y" Action="{!yyy}"/>
                <apex:commandLink value="Z" Action="{!zzz}"/>
                <apex:commandLink value="All" Action="{!all}"/>                
            </apex:toolbarGroup>
        </apex:toolbar>
        </right>

                <apex:pageBlockTable value="{!CandidateList}" var="CadList"  title="Click Column Header for Sorting"  styleclass="textalign" headerClass="textalign" >
                    <apex:column >
                        <apex:facet name="header">
                           <apex:commandLink value="Name" action="{!toggleSort}" rerender="pgblock">
                                <!-- Value attribute should have field (API Name) to sort in asc or desc order -->
                                <apex:param name="sortField" value="Name" assignTo="{!sortField}"/>
                           </apex:commandLink>
                        </apex:facet>
                        <apex:outputField value="{!CadList.Name}"/>
                    </apex:column> 

                    <apex:column >
                        <apex:facet name="header">
                            <apex:commandLink value="Phone" action="{!toggleSort}" rerender="pgblock">
                                <apex:param name="sortField" value="Phone" assignTo="{!sortField}"/>
                            </apex:commandLink>
                        </apex:facet>
                        <apex:outputField value="{!CadList.Phone}"/>
                    </apex:column>

                  <!--  <apex:column >
                        <apex:facet name="header">
                            <apex:commandLink value="Name" action="{!toggleSort}" rerender="pgblock">
                                <apex:param name="sortField" value="Email" assignTo="{!sortField}"/>
                            </apex:commandLink>
                        </apex:facet>
                        <apex:outputField value="{!CadList.Email}"/>
                    </apex:column>-->

                    <apex:column >
                        <apex:facet name="header">
                            <apex:commandLink value="Type" action="{!toggleSort}" rerender="pgblock">
                                <apex:param name="sortField" value="Type" assignTo="{!sortField}"/>
                            </apex:commandLink>
                        </apex:facet>
                        <apex:outputField value="{!CadList.Type}"/>
                    </apex:column>

                    <apex:column >
                        <apex:facet name="header">
                            <apex:commandLink value="OwnerName" action="{!toggleSort}" rerender="pgblock">
                                <apex:param name="sortField" value="Owner.Name" assignTo="{!sortField}"/>
                            </apex:commandLink>
                        </apex:facet>
                        <apex:outputField value="{!CadList.Owner.Name}"/>
                    </apex:column>

                    <apex:column >
                        <apex:facet name="header">
                            <apex:commandLink value="Website" action="{!toggleSort}" rerender="pgblock">
                                <apex:param name="sortField" value="Website" assignTo="{!sortField}"/>
                            </apex:commandLink>
                        </apex:facet>
                        <apex:outputField value="{!CadList.Website}"/>
                    </apex:column>
                </apex:pageBlockTable>
            <!---</apex:pageBlockSection>---->

            <apex:panelGrid columns="6">
                <apex:commandLink action="{!first}">First</apex:commandlink>
                <apex:commandLink action="{!previous}" rendered="{!hasPrevious}">Previous</apex:commandlink>
                <apex:commandLink action="{!next}" rendered="{!hasNext}">Next</apex:commandlink>
                <apex:commandLink action="{!last}">Last</apex:commandlink>
                <apex:inputText value="{!pageNumber}"> PageNumber</apex:inputText> of 4
            </apex:panelGrid>

        </apex:pageBlock>
    </apex:form>
</apex:page>

For answer's thanks in advance.

  • 1
    Refresh the current result of the page and showing the same result" can you explain it bit more – Tushar Sharma Nov 1 '16 at 5:50
  • @TusharSharma if I click the refresh button it's refresh the page block table but it's not affect any result of the page just loading and provide the what's the actual result of the page in previous(before refresh) that same result is appeared in after it loading .If still you not clear just know to me. – MohanRaj Nov 1 '16 at 5:54
  • Your refresh method does nothing in code, You want it to simply refresh and present you with a new page(clear page) or should it do something before showing the same page? – C. Praveenkumar Nov 1 '16 at 6:36
  • 1
    So, what you want your Refresh button to do? Do you want it to save the result and come back to same page OR Do you want it refresh the page and clear the results(and not save)? – C. Praveenkumar Nov 1 '16 at 6:45
  • 1
    Still am not pretty much sure about what has to be done, coz you are displaying all the accounts in page like standard list page with all pagination and sorting. As a standard page Refresh button does nothing but refresh the current page and clear all the selections. But if you really want to save the selected records, You have to write a Wrapper class and get all the Selected records into a wrapper list and save it(write this in your refresh method). – C. Praveenkumar Nov 1 '16 at 7:20
1

Please use the below code in you apex, to get ur desired action for Refresh button

PageReference pageRef = new PageReference(ApexPages.currentPage().getUrl()); 
pageRef.setRedirect(true); 
return pageRef;
1

when you using onclick property it should refer to javascript function

<apex:commandButton onclick="{!refresh()}"/>

But if you want to reference function in your controller you should write:

<apex:commandButton action="{!refresh}" value="Refresh"/>

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.