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
anu123anu123 

how to get previous record id in account object.

Hi all,

     i have a list accounts in vf page.(10 accounts)presently i am clicking on 5th record. how to get the 4th record id and 6th record id from controller.any method is there like previous and next based on the particular record. any one can u plz send me the code

 

 

thanks in advance

anu......

bob_buzzardbob_buzzard

How have you generated the list of records?  I.e. is this a standard set controller or are you using your own code to generate the list via a SOQL query?

anu123anu123

hi,

  thank u for ur reply..

          using standardset controller.can u send me the code how to write query for getting the previous and next record ids

 

thanks in advance

anu.......

bob_buzzardbob_buzzard

You can get at the records on the current page using the getRecords() method of the standardsetcontroller.  You will then have to iterate the list to locate the record id that the user has clicked on, and return the element at position - 1.

anu123anu123

Hi,

     Thank u for ur replay.

             please send me the code.

 

my controller is

 

 public class accountdetail{public boolean detail{set;get;}public boolean detail1{set;get;}public id cid{set;get;} public accountdetail(ApexPages.StandardSetController controller) { detail=true; detail1=false;    }         public ApexPages.StandardSetController con {get {if(con == null) {con = new ApexPages.StandardSetController(Database.getQueryLocator([Select name from account  ]));con.setPageSize(1);}return con;}set;}public Boolean hasNext {get {return con.getHasNext();}set;}public Boolean hasPrevious {get {return con.getHasPrevious();}set;}public void previous() {
con.previous();}public void next() {con.next();}        public void detail(){   detail=false;   detail1=true; }

}

 

 

page is

 

<apex:page standardController="Account" recordSetVar="accs" sidebar="false" extensions="accountdetail">  <apex:form ><apex:pageBlock title="Account">
 <apex:outputpanel rendered="{!detail}">   <apex:pageBlockTable value="{!accs}" var="acc" >   <apex:column headerValue="Account Name" >   <apex:commandLink action="{!detail}" value="{!acc.Name}" >     <apex:param name="cid" value="{!acc.id}"/>    </apex:commandLink>   </apex:column>    </apex:pageBlockTable>   </apex:outputpanel>   </apex:pageBlock>    <apex:outputPanel id="detail"  rendered="{!detail1}">    <apex:commandButton action="{!previous}" rendered="{!hasPrevious}" value="previous"/>    <apex:commandButton action="{!next}"   rendered="{!hasNext}" value="next"/>          <apex:detail subject="{!$CurrentPage.parameters.cid}" relatedList="false" title="false"/>           </apex:outputPanel> </apex:form>     </apex:page>

 

 

 

thanks in advance

 

please can u modify my code.

bob_buzzardbob_buzzard

Can you post your code using the code icon (the clipboard with a 'c' in it in the toolbar)?  otherwise its pretty difficult to understand.

anu123anu123

hi,

  thank u for ur reply.

      list of accounts like 

 

a1

-----

a2

-------

a3

-----

a4

-----

 when i click on a2 command link that detail page displayed in vf page/in that vf page placed previous and next command buttons.when click on previous command butoon it will be redirected to a1 detail page with command button next only.(because it is afirst record).when click on next button of a2 detail page it redirected to a3 detail page with previos and next buttons.(because after a3 record a4 record is there).can u please send me the code

 

thanks in advance.

anu

 

bob_buzzardbob_buzzard

I can't send you code to do this as I'd have to write it.  

 

Is the detail page a separate VF page, or is it part of the page listing all the accounts?