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
MycodexMycodex 

Pagination for simple notification page

I'm trying to create a simple messaging system for users to display on the home page. Since visualforce pages can't change their size dynamically, I was hoping to make it a static height and then create pagination (previous page and next page). I'm stuck though on how to proceed. My apex and visualforce code is pretty basic. Has anyone done this?

public class messageController {

public SLX__Change_Control__c[] getMessages() {
return [select Name, Publish_Date__c, Published_Text__c from SLX__Change_Control__c WHERE Publish_Date__c <= TODAY AND Publish_Expiration__c >= TODAY AND Published__c = TRUE ORDER BY Publish_Date__c DESC];
}
}

 

<apex:page showHeader="false" controller="messageController">
<apex:repeat value="{!Messages}" var="message">
{!message.Name}
<apex:outputText value=" - Posted on {0,date,MM/dd/yyyy}">
<apex:param value="{!message.Publish_Date__c}" /></apex:outputText>
{!message.Published_Text__c}
</apex:repeat>
</apex:page>

 

 

Best Answer chosen by Admin (Salesforce Developers) 
MycodexMycodex

Looks like I figured out what I needed using the Pagination tutorial [link]

 

For those of us who would like to know what I did, look below. This gives it a nice look and feel to the home page. The URL I used for the component was:

 

<iframe src="/apex/PublishedMessages" scrolling="no" width="100%" frameborder="0" height="450"> </iframe>

 

 

public class messageController { List<SLX__Change_Control__c> ChangeList = new List<SLX__Change_Control__c>(); List<SLX__Change_Control__c> ChangeList_Next = new List<SLX__Change_Control__c>(); Integer next = 5, count = 5; boolean shownext, showprev; Public void Search() { try { ChangeList = [select Name, Publish_Date__c, Published_Text__c from SLX__Change_Control__c WHERE Publish_Date__c <= TODAY AND Publish_Expiration__c >= TODAY AND Published__c = TRUE ORDER BY Publish_Date__c DESC]; if(ChangeList.size()>count) { for(Integer i=0; i<count; i++) ChangeList_Next.add(ChangeList[i]); shownext = true; } else ChangeList_Next = ChangeList; }catch(Exception e){system.debug('Exception :'+e);} } Public Integer GetChangeList_Size() { return ChangeList.size(); } Public List<SLX__Change_Control__c> GetMessages() { return ChangeList_Next; } Public void Next() { try { showprev = true; ChangeList_Next.clear(); Integer limit1 = 0; if(next+count < ChangeList.size()) limit1 = next+count; else { limit1 = ChangeList.size(); shownext = false; } for(Integer i=next; i<limit1; i++) ChangeList_Next.add(ChangeList[i]); Next+=count; }catch(Exception e){system.debug('Exception :'+e);} } Public void Prev() { try { shownext = true; ChangeList_Next.clear(); Integer limit1 = 0; if(next-(count+count) > 0) limit1 = next-count; else { limit1 = next-count; showprev = false; } for(Integer i=next-(count+count); i<limit1; i++) ChangeList_Next.add(ChangeList[i]); Next-=count; }catch(Exception e){system.debug('Exception :'+e);} } Public boolean getshownext(){return shownext;} Public boolean getshowprev(){return showprev;} }

 

 

<apex:page showHeader="false" controller="messageController" action="{!Search}"> <head> <link href="/dCSS/Theme2/default/common.css" type="text/css" rel="stylesheet"/> <style type="text/css" media="all"> /***** Baseline Styles *****/ body{margin: 0; padding: 0; line-height: 1.5em; font-size: .75em; font-family: Arial, Verdana; color: #000000; background-color: #FFFAFA;} p{margin: 0; padding: 0; line-height: 1.5em; font-size: .75em; font-family: Arial, Verdana; color: #000000;} /***** Custom Classes *****/ .IC_FAQs{background-color: #638658; border-color: #638658;} .IC_FAQs .pbFooter{background-color: #D95D2E;} .SectionName{margin: 5px 0 0 0;font-size: 100%; clear: both;} .Record{background-color: #F3F3EC; margin: 0; padding: 2px 2px 2px 20px; line-height: 1.5em; border-top-width: 1px; border-top-style: solid; border-top-color: #E3DEB8;} .RecordBody{color: #000000; margin: 5px 10px; font-size: 100%;} </style> </head> <apex:form id="changepage"> <div class='bPageBlock IC_FAQs'> <div class='pbBody'> <apex:commandLink value="Prev" action="{!Prev}" rendered="{!showprev}" status="GetStatus" rerender="changepage"/> <apex:commandLink value="Next" action="{!Next}" rendered="{!shownext}" status="GetStatus" rerender="changepage"/> <apex:actionStatus startText="Requesting..." id="GetStatus"/> <apex:repeat value="{!Messages}" var="message"> <p class='SectionName'> <b>{!message.Name}</b> <font size="1.5"><i><apex:outputText value=" - Posted on {0,date,MM/dd/yyyy}"> <apex:param value="{!message.Publish_Date__c}" /></apex:outputText></i></font> </p> <div class='Record'> <p class='RecordBody'>{!message.Published_Text__c}</p> <p class='RecordBody'></p> </div> </apex:repeat> </div></div> </apex:form> </apex:page>