You need to sign in to do that
Don't have an account?

Pagienation for class
Hi all ,
Can anyone help me with my code for pagienation of records........
Thanks in Advance.............
apex class :
public class objectcontroller
{
public List<selectOption> objects{get; set;}
public string selected{get; set;}
public List<contact> obj1{get; set;}
public list<lead> obj2{get; set;}
public boolean obj1Status{get; set;}
public boolean obj2Status{get; set;}
public list<wrapcontact> wrapcon{get;set;}
public list<wrapLead> wrapLd{get;set;}
public objectcontroller()
{
obj1Status=false;
obj2Status=false;
objects= new List<selectOption>();
objects.add(new selectOption('contact','contact'));
objects.add(new selectOption('lead','lead'));
wrapcon = new List<wrapcontact>();
wrapLd = new list<wrapLead>();
}
public pageReference getRecordofObject()
{
if(selected=='contact')
{
for(contact c :[select id,lastname,Email from contact limit 100]){
wrapcon.add(new wrapcontact(c));
}
obj1Status=true;
obj2status=false;
}
else
{
for(lead l:[select name,company,Status from lead limit 100]){
wrapLd.add(new wrapLead(l));
}
obj1status=false;
obj2Status=true;
}
return null;
}
public class wrapcontact {
public contact con {get; set;}
public Boolean selected {get; set;}
public wrapcontact(contact a) {
con = a;
selected = false;
}
}
public class wraplead{
public lead Ld {get; set;}
public Boolean selected {get; set;}
public wraplead(lead a) {
Ld = a;
selected = false;
}
}
}
Visulaforce page :
<apex:page controller="objectcontroller" showHeader="false">
<apex:form >
<apex:pageBlock title="Select a object">
<apex:selectList value="{!selected}" size="1">
<apex:selectOptions value="{!objects}"/>
</apex:selectList>
<apex:pageBlockButtons location="bottom">
<apex:commandButton action="{!getRecordofObject}" value="Show Records" rerender="cb"/>
</apex:pageBlockButtons>
</apex:pageBlock>
<apex:outputPanel >
<apex:pageBlock id="cb">
<apex:pageBlockSection >
<apex:pageBlockTable value="{!wrapcon}" var="ob1" rendered="{!obj1Status}">
<apex:column >
<apex:inputCheckbox value="{!ob1.selected}" id="inputId"/>
</apex:column>
<apex:column value="{!ob1.con.id}"/>
<apex:column value="{!ob1.con.lastname}"/>
<apex:column value="{!ob1.con.Email}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
<apex:pageBlockSection >
<apex:pageBlockTable value="{!wrapLd}" var="ob2" rendered="{!obj2Status}">
<apex:column >
<apex:inputCheckbox value="{!ob2.selected}" id="inputId"/>
</apex:column>
<apex:column value="{!ob2.Ld.id}"/>
<apex:column value="{!ob2.Ld.company}"/>
<apex:column value="{!ob2.Ld.status}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:outputPanel>
</apex:form>
Thanks in advance........
Can anyone help me with my code for pagienation of records........
Thanks in Advance.............
apex class :
public class objectcontroller
{
public List<selectOption> objects{get; set;}
public string selected{get; set;}
public List<contact> obj1{get; set;}
public list<lead> obj2{get; set;}
public boolean obj1Status{get; set;}
public boolean obj2Status{get; set;}
public list<wrapcontact> wrapcon{get;set;}
public list<wrapLead> wrapLd{get;set;}
public objectcontroller()
{
obj1Status=false;
obj2Status=false;
objects= new List<selectOption>();
objects.add(new selectOption('contact','contact'));
objects.add(new selectOption('lead','lead'));
wrapcon = new List<wrapcontact>();
wrapLd = new list<wrapLead>();
}
public pageReference getRecordofObject()
{
if(selected=='contact')
{
for(contact c :[select id,lastname,Email from contact limit 100]){
wrapcon.add(new wrapcontact(c));
}
obj1Status=true;
obj2status=false;
}
else
{
for(lead l:[select name,company,Status from lead limit 100]){
wrapLd.add(new wrapLead(l));
}
obj1status=false;
obj2Status=true;
}
return null;
}
public class wrapcontact {
public contact con {get; set;}
public Boolean selected {get; set;}
public wrapcontact(contact a) {
con = a;
selected = false;
}
}
public class wraplead{
public lead Ld {get; set;}
public Boolean selected {get; set;}
public wraplead(lead a) {
Ld = a;
selected = false;
}
}
}
Visulaforce page :
<apex:page controller="objectcontroller" showHeader="false">
<apex:form >
<apex:pageBlock title="Select a object">
<apex:selectList value="{!selected}" size="1">
<apex:selectOptions value="{!objects}"/>
</apex:selectList>
<apex:pageBlockButtons location="bottom">
<apex:commandButton action="{!getRecordofObject}" value="Show Records" rerender="cb"/>
</apex:pageBlockButtons>
</apex:pageBlock>
<apex:outputPanel >
<apex:pageBlock id="cb">
<apex:pageBlockSection >
<apex:pageBlockTable value="{!wrapcon}" var="ob1" rendered="{!obj1Status}">
<apex:column >
<apex:inputCheckbox value="{!ob1.selected}" id="inputId"/>
</apex:column>
<apex:column value="{!ob1.con.id}"/>
<apex:column value="{!ob1.con.lastname}"/>
<apex:column value="{!ob1.con.Email}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
<apex:pageBlockSection >
<apex:pageBlockTable value="{!wrapLd}" var="ob2" rendered="{!obj2Status}">
<apex:column >
<apex:inputCheckbox value="{!ob2.selected}" id="inputId"/>
</apex:column>
<apex:column value="{!ob2.Ld.id}"/>
<apex:column value="{!ob2.Ld.company}"/>
<apex:column value="{!ob2.Ld.status}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:outputPanel>
</apex:form>
Thanks in advance........
I have gone through your query and writing an example of pagination in the VF page.
I hope it will work for you as you desire.
VF page- ------------------------------------------------------------
Controller class-
If you still have more queries please let me know.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com
I have gone through your problem please refer below code:
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com
Thanks for your code but i am facing error like
List index out of bounds: 2
An unexpected error has occurred. Your development organization has been notified. and also i want to add wraper class to it..
can you go through it........................................................