function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Varun99Varun99 

pagination in visualforce

Hi,

       I have developed a visual force page and am tring to pagination my page but am not getting

this concept plase help me.

this is my code all contacts update

 

 

<apex:page controller="contactstoupdate" showHeader="false" sidebar="false">
<apex:form >
<apex:pageBlock rendered="{!clist}">
<apex:pageBlockTable value="{!conlist}" var="acc">
<apex:column headerValue="Contacts" >
<apex:commandLink value="{!acc.name}" action="{!condetail}">
<apex:param name="conname" value="{!acc.id}"/>
</apex:commandlink>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:panelGrid columns="4">
<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:panelGrid>
<apex:pageblock rendered="{!condetail}" title="Contact detail page" >
<apex:pageBlockButtons >
<apex:commandButton value="Edit" action="{!Edit}"/>
</apex:pageBlockButtons>
<apex:pageblockSection >
<apex:outputField value="{!con.lastname}"/>
<apex:outputField value="{!con.phone}"/>
<apex:outputField value="{!con.email}"/>
</apex:pageblockSection>
</apex:pageblock>
<apex:pageBlock rendered="{!conedit}">
<apex:pageblockButtons >
<apex:commandButton value="save" action="{!save}"/>
<apex:commandButton value="back" action="{!back}"/>
</apex:pageblockButtons>
<apex:pageblockSection >
<apex:inputField value="{!con.lastname}"/>
<apex:inputField value="{!con.phone}"/>
<apex:inputField value="{!con.email}"/>
</apex:pageblockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

 

======================================================

 

public class contactstoupdate
{
public boolean clist{set;get;}
public boolean condetail{set;get;}
public boolean conedit{set;get;}
//public boolean hasprevious{set;get;}
//public boolean hasnext{set;get;}
list<contact> conlist=new list<contact>();

contact con=new contact();
public contactstoupdate()
{
clist=true;
condetail=false;
conedit=false;
for(contact c:[select id,name from contact])
conlist.add(c);
system.debug('@@@@@@'+conlist);
}

public ApexPages.StandardSetController con1 {
get {
if(con1==null)
{
con1 = new ApexPages.StandardSetController(Database.getQueryLocator([Select Id, Name FROM Contact limit 100]));
// sets the number of records in each page set
con1.setPageSize(5);
}
return con1;
}
set;
}
public Boolean hasNext {
get {
return con1.getHasNext();
}
set;
}
public Boolean hasPrevious {
get {
return con1.getHasPrevious();
}
set;
}
public Integer pageNumber {
get {
return con1.getPageNumber();
}
set;
}

 

public list<contact> getconlist()
{
return conlist;
}
public void condetail()
{
clist=false;
condetail=true;
id i=Apexpages.currentpage().getparameters().get('conname');
con=[select id,lastname,phone,email from contact where id=:i];
}
public void edit()
{
conedit=true;
condetail=false;
clist=false;
}
public void back()
{
condetail=true;
conedit=false;
clist=false;
}
public void save()
{
condetail=true;
conedit=false;
clist=false;
update con;
}
public contact getcon()
{
return con;
}
public void first()
{
con1.first();
}
public void previous()
{
con1.previous();
}
public void next()
{
con1.next();
}
public void last()
{
con1.last();
}
}

 

 

 

 

Thank you.

PremanathPremanath

Hi try this code in opportunity object

 

<apex:page controller="opportunityList2Con">
    <apex:sectionHeader Title="This is a Set Controller Test" subtitle="There are a total of {!reccount} Records in this list" title="Oppurtunity"/>
    <apex:pageBlock >
        <apex:form >
        <apex:pageBlockTable value="{!opportunities}" var="o">
            <apex:column value="{!o.name}"/>
            <apex:column value="{!o.closedate}"/>
        </apex:pageBlockTable>
        <apex:commandLink action="{!previous}">Previous</apex:commandlink> &nbsp;
    <apex:commandLink action="{!next}">Next</apex:commandlink> 

        </apex:form>
    </apex:pageBlock>
</apex:page>
public class opportunityList2Con {

    public Integer getReccount() {
        return setCon.getResultSize();
    }

    
    Public void Next(){
        setCon.next();        
    }

    Public void Previous(){
        setCon.previous();
    }

    public string qry='select name,closedate from Opportunity limit 9999';
    public ApexPages.StandardSetController setCon {get {
            if(setCon == null) {setCon = new ApexPages.StandardSetController(Database.getQueryLocator(qry));
            }
            setCon.setPageSize(10);
            return setCon;
        }set;
    }
    public List<Opportunity> getOpportunities() {
         return (List<Opportunity>) setCon.getRecords();
    }
}
Varun99Varun99

Thank you it's working i found my error.

 

 

Vishal GuptaVishal Gupta
Also further if u feel any problem you should refer to visualforce development pdf's.