You need to sign in to do that
Don't have an account?
How to retrieve only 5 records per page
Hi All, i am new to VisualForce so please help me.... here are my page and controller::::::::::
public class AccountSearchPGController {
String searchText;
List<Account> results;
public String getSearchText() {
return searchText;
}
public void setSearchText(String s) {
searchText = s;
}
public List<Account> getResults() {
return results;
}
public PageReference doSearch() {
//results = (List<Account>)[FIND :searchText RETURNING Account(Name, Type, Phone)][0];
results = [SELECT name,type,phone FROM Account];
return null;
}
}
////////////////////pagee///////////////////////////////////
<apex:page controller="AccountSearchPGController">
<apex:form >
<apex:pageBlock mode="edit" id="block">
<apex:pageBlockSection title="Account Search Page">
<apex:pageblockSectionItem >
<apex:outputLabel for="searchText">Search Text</apex:outputLabel>
<apex:panelGroup >
<apex:inputText id="searchText" value="{!searchText}"/>
<apex:commandButton value="Search" action="{!doSearch}" rerender="block" status="status"/>
</apex:panelGroup>
</apex:pageblockSectionItem>
</apex:pageblockSection>
<apex:actionStatus id="status" startText="requesting..."/>
<apex:pageBlockSection title="Results" id="results" columns="1">
<apex:pageBlockTable rows="5" value="{!results}" var="l" rendered="{!NOT(ISNULL(results))}">
<apex:column value="{!l.name}"/>
<apex:column value="{!l.type}"/>
<apex:column value="{!l.phone}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Hi,
You need to use paging to work around on this. You have to create a custom function to implement the 5 records per page. You have to create a first, next option so that you can set 5 records per page. Initially set the flag variable to 5 and process the business logic according to that.
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Try below query, it will return only 5 records.
results = [SELECT name,type,phone FROM Account limit 5];
Is this helpful?
You can use standardset methods for the paginations. You can set recordsize per page.
visit the below link for more details
http://www.salesforce.com/us/developer/docs/pages/Content/apex_pages_standardsetcontroller.htm
Regards,
I have an example for pagnation and it can be set page size to 5. Here it is.
Just copy and paste. feel the pagination :)
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.
Smart move Chamil :)
Here is the source :D
http://forceguru.blogspot.com/2011/04/pagination-in-salesforce.html
Thanks
Ankit Arora
Blog | Facebook | Blog Page
Sorry Ankith. I couldn't find the link for that code and I didn't remember the code is from your blog. But I have this example once for my requirement. So I posted modified code for this post. I wanted to help this guy with good solution.