Link to home
Start Free TrialLog in
Avatar of -Dman100-
-Dman100-Flag for United States of America

asked on

how do you calculate the last page of results in a list

I'm trying to calculate the first and last page of records in a list.  For example, if the returned list contained 100 records and page could display 10 records per page, I am trying to create a method to grab the first 10 records for a link that would take the user to the first 10 records in the list and then another link "last" that would take the user to the last 10 records in the list.

I have an existing method that takes the user to the next and previous set of records (see code below).  How can I get the first and last pages?

This relates to Salesforce apex programming, but I'm asking in the .net and c# zones because the logic should be similar.

Thanks for any help.
/* getlistContact returns the list of Contacts upto 10 per page implementing pagination*/    
    Public List<Contact> getlistContact()
    {
      return contactList_Next ;
    }
    
    /*  Previous method has the logic for displaying the list of Next contacts from Contact object implementing pagination*/ 
    Public void Next()
    { 
        try
        {
            showprev = true;
            contactList_Next.clear();
            Integer limit1 = 0;
  
            if(next+countPerPage < contactList.size())
                limit1 = next+countPerPage;
            else
            {
                limit1 = contactList.size();
                shownext = false;
            }
                
            for(Integer i=next; i<limit1; i++)
            contactList_Next.add(contactList[i]);
    
            Next+=countPerPage;
            
        }catch(Exception e){system.debug('Exception :'+e);}
    }
    
  /*  Previous method has the logic for displaying the list of previous contacts from Contact object implementing pagination*/    
    Public void Prev()
    {
        try
        {
            shownext = true;
            contactList_Next.clear();
            Integer limit1 = 0;        
            if(next-(countPerPage+countPerPage) > 0)
                limit1 = next-countPerPage;
            else
            {
                limit1 = next-countPerPage; 
                showprev = false;
            }
    
            for(Integer i=next-(countPerPage+countPerPage); i<limit1; i++)    
            contactList_Next.add(contactList[i]);
            Next-=countPerPage; 
        }catch(Exception e){
          system.debug('Exception :'+e);
        }               
    }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of DalHorinek
DalHorinek
Flag of Czechia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Ravi Vaddadi
Ravi Vaddadi
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial