• Hema Rama Krishna Kadamati
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
I wrote a code which includes several functionalities and in which pagination also includes, my other functionalities are working good but the pagination is not working. Can anyone please look at it.

Visual force Page
<apex:page Controller="profileListDisplaying2" sidebar="false" tabStyle="Account">
    <script type="text/javascript">
    function selectAllCheckboxes(obj,receivedInputID)
    {
        var inputCheckBox = document.getElementsByTagName("input");
        for(var i=0; i<inputCheckBox.length; i++)
        {
        if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1)
        {
            inputCheckBox[i].checked = obj.checked;
        }
        }
    }
    function doSearch()
    {
        searchServer(document.getElementById("Name").value);
        searchServer1(document.getElementById("Name1").value);
    }
    </script>
    <apex:form >
    <apex:pageBlock >
        <apex:actionFunction name="searchServer" action="{!search}" rerender="table">
          <apex:param name="Name" value="" />
      </apex:actionFunction>
      <table>
      <tr>
        <td style="font-weight:bold;">
        <input type="text" id="Name" style="margin: 30px 0px -50px 150px;" onkeyup="doSearch();"/>
        </td>
      </tr>  
      </table>
      <apex:actionFunction name="searchServer1" action="{!search}" rerender="table2">
          <apex:param name="Name" value="" />
      </apex:actionFunction>
      <table>
      <tr>
        <td style="font-weight:bold;">
        <input type="text" id="Name1" style="margin: 30px 0px -30px 800px;" onkeyup="doSearch();"/>
        </td>
      </tr>  
      </table>
              <!--<apex:commandButton value="Search Profiles" action="{!search}"/>-->
        <!--<apex:pageBlockButtons>-->
            <apex:commandButton value="Process" action="{!processSelected}" style="margin: 0px 310px 0px 350px;" rerender="table2,table"/>
            <apex:commandButton value="Reprocess" action="{!reprocessSelected}" rerender="table,table2"/>
        <!--</apex:pageBlockButtons>-->
        <apex:actionFunction name="refreshPageSize" action="{!refreshPageSize}" status="fetchStatus" reRender="table"/>
        <apex:panelGrid columns="8"> 

                <apex:selectList value="{!size}" multiselect="false" size="1" onchange="refreshPageSize();">
                    <apex:selectOptions value="{!paginationSizeOptions}"/>
                </apex:selectList>

                <apex:commandButton status="fetchStatus" reRender="table" value="First" action="{!setCon.first}" disabled="{!!setCon.hasPrevious}" title="First Page"/> 

                <apex:commandButton status="fetchStatus" reRender="table" value="Previous" action="{!setCon.previous}" disabled="{!!setCon.hasPrevious}" title="Previous Page"/> 

                <apex:commandButton status="fetchStatus" reRender="table" value="Next" action="{!setCon.next}" disabled="{!!setCon.hasNext}" title="Next Page"/> 

                <apex:commandButton status="fetchStatus" reRender="table" value="Last" action="{!setCon.last}" disabled="{!!setCon.hasNext}" title="Last Page"/> 

                <apex:outputText >{!(setCon.pageNumber * size)+1-size}-{!IF((setCon.pageNumber * size)>noOfRecords, noOfRecords,
                     (setCon.pageNumber * size))} of {!noOfRecords}
                </apex:outputText> 

                <apex:outputPanel >                      
                    <apex:actionStatus id="fetchStatus" >
                        <apex:facet name="start" >
                          <img src="/img/loading.gif" />                    
                        </apex:facet>
                    </apex:actionStatus>
                </apex:outputPanel> 

            </apex:panelGrid>
        <apex:pageblockSection collapsible="false" columns="2">
            <apex:outputPanel layout="block" style="width:550px;height:400px" >
                <apex:pageBlockTable value="{!wrapObjectList}" var="objWrap" id="table">
                    <apex:column >
                        <apex:facet name="header">
                                <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')" label="leftTable"/>
                        </apex:facet>
                    <apex:inputCheckbox value="{!objWrap.selected}" id="inputId"/>
                  </apex:column>
                  <apex:column value="{!objWrap.objt.Name}" headerValue="Accounts"/>
            </apex:pageBlockTable>
          </apex:OutputPanel>
          <!-- second output apanel -->
          <apex:outputPanel layout="block" style="overflow:auto;width:550px;height:400px" >
            <apex:pageBlockTable value="{!selectedObjects}" var="c" id="table2" title="Selected Accounts">
                <apex:column >
                    <apex:facet name="header">
                        <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId1')"/>
                    </apex:facet>
                    <apex:inputCheckbox value="{!c.selected}" id="inputId1"/>
                </apex:column>
                <apex:column value="{!c.objt.Name}" headerValue="Selected Accounts "/>
            </apex:pageBlockTable>
          </apex:OutputPanel>
        </apex:pageblockSection>
      </apex:pageBlock>
    </apex:form>
</apex:page>

Controller Class
public class profileListDisplaying2
    {
    public String soql{get;set;}
    Public Integer size{get;set;} 
    Public Integer noOfRecords{get; set;} 
    public List<SelectOption> paginationSizeOptions{get;set;}

    //Our collection of the class/wrapper objects wrapObject
    public boolean returnValue {get; set;}
    public List<wrapObject> wrapObjectList {get; set;}
    public List<wrapObject> wrapObjectList1 {get; set;}
    public List<wrapObject> selectedObjects{get; set;}
    //public list<Profile> acc {get;set;}  
    public string searchstring {get;set;} 
    public List<Account> notselectedObjects{get;set;}
    public List<wrapObject> notselectedObjects1{get;set;}
    public List<wrapObject> TmpList=new List<wrapObject>();
    public profileListDisplaying2()
    {
        size=10;
        paginationSizeOptions = new List<SelectOption>();
        paginationSizeOptions.add(new SelectOption('5','5'));
        paginationSizeOptions.add(new SelectOption('10','10'));
        paginationSizeOptions.add(new SelectOption('20','20'));
        paginationSizeOptions.add(new SelectOption('50','50'));
        paginationSizeOptions.add(new SelectOption('100','100'));
        paginationSizeOptions.add(new SelectOption('250','250'));
        if(wrapObjectList == null) {
           wrapObjectList = new List<wrapObject>();
            for ( Account a:Database.Query('SELECT Name FROM Account'))
            {    
                // As each object is processed we create a new wrapObject object and add it to the wrapObjectList              
                wrapObjectList.add(new wrapObject(a));               
                }
            }
            selectedObjects = new List<wrapObject>();
        }
        public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {                
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
                      [select id,Name from Account]));
                setCon.setPageSize(size);  
                noOfRecords = setCon.getResultSize();
            }            
            return setCon;
        }
        set;
    }
    public PageReference refreshPageSize() {
         setCon.setPageSize(size);
         return null;
    }
    public List<Account> getwrapObjectList() {
         return (List<Account>) setCon.getRecords();
    }
    public void search()
    {
    list<Account> lstprofiles=new list<Account>();  

       String Name = Apexpages.currentPage().getParameters().get('Name');
       soql = 'select Name from account';
       if (!Name.equals(''))
       {
           soql += ' where Name LIKE \''+String.escapeSingleQuotes(Name)+'%\' order by Name';
       }
     lstprofiles= Database.query(soql);
     wrapObjectList=new List<wrapObject>();
     for(Account pr:lstprofiles)
     {
       wrapObject objwrap1=new wrapObject(pr);

     wrapObjectList.add(objwrap1);
     }
     }

      public void processSelected() {

          notselectedObjects=new List<Account>();
        for(wrapObject wrpObj : wrapObjectList) {
            if(wrpObj.selected == true) {
               TmpList.add(wrpObj);
               for(wrapObject obj:Tmplist){
               obj.selected=false;
               }
               selectedObjects=TmpList;               
               }
               else {
                   notselectedObjects.add(wrpObj.objt );
                }               
         }          
          wrapObjectList = new List<wrapObject>();          
          for(Account b: notselectedObjects)  {
            wrapObjectList.add(new wrapObject(b));
          }                                
        }    
         public void reprocessSelected() {
               notselectedObjects1=new List<wrapObject>();           
           for(wrapObject wrpObj1 : selectedObjects){
            if(wrpObj1.selected == true){
              wrapObjectList.add(wrpObj1);
              } 
              else
              {
                   notselectedObjects1.add(wrpObj1);
                }                                                         
        }
         selectedObjects = new List<wrapObject>();
         for(wrapObject ns : notselectedObjects1)  {
            selectedObjects.add(ns);
          }
        }             
    // This is our wrapper/container class. In this example a wrapper class contains both the standard salesforce object and a Boolean value
    public class wrapObject {
        public Account objt {get; set;}         
        public Boolean selected {get; set;} 
        public wrapObject(Account a) {
            objt = a;
            selected = false;            
        }
    }
}

I want to create a VisualFroce page having input fields in it. I want this page to enable Guest User to enter new record in Account Object( or any other Object).

I want headStart on how to write code for Save/Search/Edit/Delete Functions on a visulaForce page.
(Assume that i have created required input fields on visualFroce Page)
 
I can do this using Flow but i want to acheive this using VisualForce Page.

Even a link to similar solved question would do.

PS: Salesforce is new to me.

  • February 27, 2015
  • Like
  • 0