Clickjack in Salesforce

Check this link

http://help.salesforce.com/apex/HTViewSolution?id=000145603&language=en_US


Cheers!!!

Session Settings in Salesforce

Set the session security and session expiration timeout for your organization.

1. Go to Setup --> Administration Setup --> Security Controls --> Session Settings.

2. Fill in the details.

3. Click "Save" button.


Field
Description
Timeout value
Length of time after which the system logs out inactive users. Select a value between 15 minutes and 12 hours. Choose a shorter timeout period if your organization has sensitive information and you want to enforce stricter security.Note
The last active session time value isn’t updated until halfway through the timeout period. That is, if you have a 30 minute timeout, the system won’t check for activity until 15 minutes have passed. For example, assume you have a 30 minute timeout value. If you update a record after 10 minutes, the last active session time value won’t be updated because there was no activity after 15 minutes. You’ll be logged out in 20 more minutes (30 minutes total) because the last active session time wasn’t updated. Suppose you update a record after 20 minutes. That’s five minutes after the last active session time is checked, so your timeout resets and you have another 30 minutes before being logged out, for a total of 50 minutes.
Disable session timeout warning popup
Determines whether the system prompts inactive users with a timeout warning message. Users are prompted 30 seconds before timeout as specified by the Timeout value.
Lock sessions to the IP address from which they originated
Determines whether user sessions are locked to the IP address from which the user logged in; helping to prevent unauthorized persons from hijacking a valid session.Note
This may inhibit various applications and mobile devices.
Require secure connections (HTTPS)
Determines whether HTTPS is required to log in to or access Salesforce, apart from Force.com sites, which can still be accessed using HTTP.
This option is enabled by default for security reasons. It should not be disabled. Once this preference is set to require HTTPS, you can’t manually change it. To change to HTTP, contact your salesforce.com representative.
The Resetting Passwords page can only be accessed using HTTPS.
Force relogin after Login-As-User
Determines whether an administrator that is logged in as another user is returned to their previous session after logging out as the secondary user.
If the option is enabled, an administrator must log in again to continue using Salesforce after logging out as the user; otherwise, the administrator is returned to their original session after logging out as the user.
Require HttpOnly attribute
Restricts session ID cookie access. A cookie with the HttpOnly attribute is not accessible via non-HTTP methods, such as calls from JavaScript.Note
If you have a custom or packaged application that uses JavaScript to access session ID cookies, selecting Require HttpOnly attribute breaks your application because it denies the application access to the cookie. The Developer Console and AJAX Toolkit debugging window are also not available if the Require HttpOnly attribute is selected.
Enable caching and password autocomplete on login page
Allows the user’s browser to store usernames. If enabled, after an initial log in, usernames are auto-filled into the User Name field on the login page. This preference is selected by default and caching and autocomplete are enabled.
Enable SMS-based identity confirmation
Enables users to receive a one-time PIN delivered via SMS. Once enabled, administrators or users must verify their mobile phone number before taking advantage of this feature.
Login IP Ranges
Specifies a range of IP addresses users must log in from (inclusive), or the login will fail. Users need to activate their computers to successfully log in from IP addresses outside this range.
To specify a range, click New and enter a lower and upper IP address to define the range.
This field is not available in Enterprise, Unlimited, and Developer Editions. In those editions, you can specify valid IP addresses per profile.
Enable clickjack protection for non-setup Salesforce pages
Protects against clickjack attacks on non-setup Salesforce pages. Clickjacking is also known as a user interface redress attack. Setup pages already include protection against clickjack attacks. (Setup pages are those pages accessed from the left side of the screen after clicking Your Name | Setup on the upper-right part of the user interface.)
Enable clickjack protection for non-setup customer Visualforce pages
Protects against clickjack attacks on your Visualforce pages. Clickjacking is also known as a user interface redress attack. Warning
If you use custom Visualforce pages within a frame or iframe, you may see a blank page or the page may display without the frame. For example, Visualforce pages in a page layout do not function when clickjack protection is on.

How to restrict users Login IP Ranges for Your Organization in Salesforce?

1. Click Your Name --> Setup --> Security Controls --> Network Access.

2. Click "New" button.


3. Enter a valid IP address in the Start IP Address field and a higher IP address in the End IP Address field.

The start and end addresses define the range of allowable IP addresses from which users can log in. If you want to allow logins from a single IP address, enter the same address in both fields. For example, to allow logins from only 125.12.3.0, enter 125.12.3.0 as both the start and end addresses.

For example, the following ranges are valid:

        0.0.0.0 to 1.255.255.255
        132.0.0.0 to 132.255.255.255
        132.0.0.0 to 133.255.255.255

However, ranges like 0.0.0.0 to 2.255.255.255 or 132.0.0.0 to 134.0.0.0 are too large.


4. Click "Save" button.

How to assign a case to a group email id instead of assigning it to queue members?

  1. Go to Setup --> Administration Setup --> Manage Users --> Queues.
  2. Select the Queue.
  3. Set "Queue Email" to the group email.
  4. Uncheck the "Send Email to Members" checkbox.


Cheers!!!

How to change Opportunity owner for bulk of Opportunities in Salesforce?

  1. Export the Opportunities to which owner has to be changed.
  2. While exporting select Opportunity ID(Id) and Owner ID(ownerId) without fail.
  3. Modify the ownerId with the user Id of the user to which Opportunities has to be assigned.
  4. Now update the Opportunities.
Cheers!!!

How to find number of days between two Dates in Apex?

Sample Code:

public Integer temp;

public Date d {get ; set;}

temp = d.daysBetween(Date.Today()); // Returns Number of days between d and today.

With sharing and without sharing in Apex Class

With sharing and without sharing in Apex Class determines whether the class should enforce all the Organization sharing settings.

Example:

Visualforce page:

<apex:page sidebar="false" controller="Sample">
    <apex:form >
       <apex:pageblock >
            <apex:pageblockTable value="{!var}" var="a">
                <apex:column value="{!a.Name}"/>
            </apex:pageblockTable>
        </apex:pageblock>   
    </apex:form>
</apex:page>


Apex Class:

public with Sharing class Sample
{
    public List<Account> getVar()
    {
        return [SELECT Name FROM Account];
    }    
}


OWD for Account is Private.



Role Hierarchy:


Output of the page for Managing Director Role:




Output of the page for Manager Role:

How to start loading from the middle of the excel file in data loader?

1. Go to Settings in Apex Data Loader.


2. Set "Start at Row" field to start the process from the mentioned row number from the excel file.


Cheers!!!

How to change currency of Opportunity?

To change the currency of an Opportuniy, you must first delete all the products from the opportunity. Then only you will be able to edit the currency of that Opportunity.

How to bypass Governor limits in Salesforce?

readOnly attribute in apex:page tag

To enable read-only mode for an entire page, set the readOnly attribute on the <apex:page> component to true. For example, here is a simple page that will be processed in read-only mode:

<apex:page controller="SummaryStatsController" readOnly="true">
    <p>Here is a statistic: {!veryLargeSummaryStat}</p>
</apex:page>


The controller for this page is also simple, but illustrates how you can calculate summary statistics for display on a page:

public class SummaryStatsController 
{
    public Integer getVeryLargeSummaryStat() 

   {
        Integer closedOpportunityStats =
            [SELECT COUNT() FROM Opportunity WHERE Opportunity.IsClosed = true];
        return closedOpportunityStats;
    }
}


Normally, queries for a single Visualforce page request may not retrieve more than 50,000 rows. In read-only mode, this limit is relaxed to allow querying up to 1 million rows.

In addition to querying many more rows, the readOnly attribute also increases the maximum number of items in a collection that can be iterated over using components such as <apex:dataTable>, <apex:dataList>, and <apex:repeat>. This limit increased from 1,000 items to 10,000. Here is a simple controller and page demonstrating this:

public class MerchandiseController
{
    public List<Merchandise__c> getAllMerchandise()

   {
        List<Merchandise__c> theMerchandise =
            [SELECT Name, Price__c FROM Merchandise__c LIMIT 10000];
        return(theMerchandise);
    }
}

<apex:page controller="MerchandiseController" readOnly="true">
    <p>Here is all the merchandise we have:</p>
    <apex:dataTable value="{!AllMerchandise}" var="product">
        <apex:column>
            <apex:facet name="header">Product</apex:facet>
            <apex:outputText value="{!product.Name}" />
        </apex:column>
        <apex:column>
            <apex:facet name="header">Price</apex:facet>
            <apex:outputText value="{!product.Price__c}" />
        </apex:column>
    </apex:dataTable>
</apex:page>


While Visualforce pages that use read-only mode for the entire page can't use data manipulation language (DML) operations, they can call getter, setter, and action methods which affect form and other user interface elements on the page, make additional read-only queries, and so on.

Summary:

In read only mode,
  1. SOQL can retrieve upto 1 million records.
  2. Collection type limit is 10,000.
  3. We cannot do Insert, Update, Delete and Upsert operations. 
Cheers!!!

How to Edit Dated Exchange Rates in multiple currencies in Salesforce?


To add new dated exchange rates:
  1. Click Your Name | Setup | Company Profile | Manage Currencies.
  2. Click Manage Dated Exchange Rates.
  3. Click New Exchange Rates.
  4. Enter the date that the exchange rates go into effect.
  5. Enter the exchange rates.
  6. Click Save to save the new dated exchange rates.
To view existing dated exchange rates:
  1. Click Your Name | Setup | Company Profile | Manage Currencies.
  2. Click Manage Dated Exchange Rates.
  3. Select the date range you want to view either by entering the date and clicking Go!, or by selecting Previous Range or Next Range.
To delete a dated exchange rate for a particular currency:
  1. Click Your Name | Setup | Company Profile | Manage Currencies.
  2. Click Manage Dated Exchange Rates.
  3. Click the name of the currency you want to edit.
  4. Click Del for the date range you want to delete.
    If the date range you want is not displayed, enter it in the Show all rates with start dates between fields and click Go!.
To edit your dated exchange rates for a particular currency:
  1. Click Your Name | Setup | Company Profile | Manage Currencies.
  2. Click Manage Dated Exchange Rates.
  3. Click the name of the currency you want to edit.
  4. Click Edit for the date range you want to edit. If the date range you want is not displayed, enter it in the Show all rates with start dates between fields and click Go!.
  5. Edit the exchange rate, setting it to the new value for the date range, and click Save.

How to Edit Conversion Rates in multiple currencies in Salesforce?


You can manage exchange rates between your active and inactive currencies and the corporate currency by editing the conversion rates. These are static exchange rates that apply to all currency fields used in your organization. In addition to these conversion rates, your organization may also use dated exchange rates for opportunities and opportunity products. For more information about dated exchange rates, see About Advanced Currency Management.

To edit your organization's static conversion rates:
1.      Click Your Name | Setup | Company Profile | Manage Currencies.
2.      If advanced currency management is enabled, click Manage Currencies.
3.      Click Edit Rates in the Active Currencies or Inactive Currencies lists.
4.      Enter the conversion rate between each currency and your corporate currency.
5.      Click Save.

When you change the conversion rates, currency amounts are updated using the new rates. Previous conversion rates are not stored. All conversions within opportunities, forecasts, and other amounts use the current conversion rate.
If your organization uses advanced currency management, you can also manage dated exchange rates for currency fields on opportunities and opportunity products. 

Cheers!!!

Enabling or Disabling Advanced Currency Management in Salesforce


To enable advanced currency management:
  1. Enable multiple currencies for your organization. For more information, see Managing Multiple Currencies.
  2. Click Your Name | Setup | Company Profile | Manage Currencies.
  3. Click Enable.
  4. When prompted, select Yes, I want to enable Advanced Currency Management and click Enable.
When advanced currency management is first enabled, your existing exchange rates automatically become the first set of dated exchange rates. These rates will be valid for all time, until you define another set of exchange rates.
To disable advanced currency management:
  1. Click Your Name | Setup | Company Profile | Manage Currencies.
  2. Click Disable.
  3. When prompted, select Yes, I want to disable Advanced Currency Management and click Disable.
If you disable advanced currency management, all currency conversions will use the static conversion rate. See Editing Conversion Rates.
When advanced currency management is enabled, Visualforce <apex:inputField> and <apex:outputField> components cannot display currency fields.

Activating and Deactivating Currencies in Salesforce.com


To use multiple currencies, your administrator must specify which currencies are supported for your organization.
  • Active currenciesThese represent countries in which your organization does business. Only active currencies can be entered in opportunities, forecasts, and other items.Once you activate a currency, you can never permanently delete it.
  • Inactive currencies—These are currencies that your organization no longer uses. You may have existing records that use inactive currencies, but you cannot enter new amounts in inactive currencies.
To activate new currencies:
  1. Click Your Name | Setup | Company Profile | Manage Currencies.
  2. Click New in the Active Currencies related list.
  3. Select a currency. Currencies are alphabetized using their ISO currency code.
  4. Enter the conversion rate relative to your corporate currency.
  5. Specify the number of decimal places to show for amounts in this currency.
  6. Click Save.
To activate a currency from the list of inactive currencies, click Activate next to the currency.
To deactivate a currency, click Deactivate next to the currency. Deactivating a currency does not alter amounts in items that use that currency. However, you can no longer enter new amounts using the inactive currency.

How to change your corporate currency in Salesforce?


  1. Click Your Name | Setup | Company Profile | Manage Currencies.
  2. Click Change Corporate.
  3. Choose a new corporate currency from the list of active currencies, and click Save.

How to Enable Multiple Currencies in Salesforce?

Contact salesforce.com to request Multiple currencies.

Be prepared to provide the following information:
  • The organization ID (production or sandbox)
  • The default currency stamp for current and future records (USD, EUR, GBP, etc.)
  • Confirmation that you understand that Multi-Currency can’t be disabled once enabled
  • Confirmation that you are a system administrator authorized on behalf of your organization to request Multi-Currency enablement and that you consent to the lockout of this organization for a certain period of time, depending on your organization’s data usage volume.

Simple Batch Apex example in Salesforce

Apex Code:

global class batchAccountUpdate implements Database.Batchable<sObject> {
    global Database.QueryLocator start(Database.BatchableContext BC) {
        String query = 'SELECT Id,Name FROM Account';
        return Database.getQueryLocator(query);
    }
   
    global void execute(Database.BatchableContext BC, List<Account> scope) {
         for(Account a : scope)
         {
             a.Name = a.Name + 'Updated';            
         }
         update scope;
    }   
    
    global void finish(Database.BatchableContext BC) {
    }
}

Run the batch apex for testing it in Developer Console.


Output:


Cheers!!!

Remote site Settings in Salesforce

When you want to access the external sites in your Salesforce application using callouts, webservices, etc... You need to add that in the Remote Site Settings. This is just a security that force.com platfom is going to check.
Before any Visualforce page, Apex callout, or JavaScript code using XmlHttpRequest in an s-control or custom button can call an external site, that site must be registered in the Remote Site Settings page, or the call will fail.

Email logs in Salesforce

1. Go to Setup --> Administration Setup --> Monitoring --> Email Log Files.


2. Click "Request an email log" button.


3. Fill in the details and click "Submit Request" button.


Output:

Salesforce Documents

Click the below link to get Salesforce documents

http://wiki.developerforce.com/page/Documentation

Link for creating Warehouse application in Salesforce

Below is the link for Warehouse Application

http://www.salesforce.com/us/developer/docs/workbook/index_Left.htm#CSHID=create_app_intro.htm|StartTopic=Content%2Fcreate_app_intro.htm|SkinName=webhelp

This workbook helps us to understand and explore Salesforce.com.

Cheers!!!

GROUP BY in SOQL

Sample SOQL:

SELECT Count(Name), OwnerId From Opportunity Where OwnerId in ('005A0000002U5TcIAK',
'005A0000002U5U1IAK', '005A0000002U5ULIA0') and StageName in ('Active - Low Probability','Active - Med. Probability','Active - High Probability','Active - Commit') GROUP BY OwnerId

Dynamic creation of outputLabel

Sample Code:

Visualforce page:


<apex:page controller="Sample" sidebar="false">
    <apex:pagemessages />
    <apex:dynamicComponent componentValue="{!lbl}"/>
</apex:page>


Apex Code:

public class Sample
{
    public Component.Apex.OutputLabel getlbl()
    {
        Component.Apex.OutputLabel lb = new Component.Apex.OutputLabel();
        lb.Value = 'Sample';
        return lb;
    }     
}



Output:


Callout not allowed from this future method. Please enable callout by annotating the future method. eg: @Future(callout=true)

In this case, use
 @future(callout=true)  
    public static void post(String u, String p)
    {
        try
        {
            HttpRequest req = new HttpRequest();
            ............................................................                   
            Http http = new Http();
            HTTPResponse res = http.send(req);           
            System.debug('Response is ' + res.getBody());

            ..................................................................
            ..................................................................
            ..................................................................
        }
        catch(Exception e)
        {
            ..................................................................

            ..................................................................
        }
    }


Cheers!!! 

Status=Length Required, StatusCode=411 error in Apex callout

HttpRequest request = new HttpRequest();

request.setHeader('Content-Length', '512');


Content-Length should be mentioned to avoid this error in callouts.

Cheers!!!

Code coverage for Task Trigger

Trigger:

trigger deletetask on Task (before delete)
    {
    if(System.Trigger.IsDelete)
        {
        for (Task t : trigger.old)
            if (t.check__c == 1)
                {
                t.addError('Error: You cannot delete a Task when it is marked complete.');
                }
        }         
}


Test Class:

@isTest
public class testClass
{
    static testmethod void test()
    {
        Task t = new Task(Type = 'Email',check__c = 0);
        insert t;
        delete t;
    }
}


Output:


Link for Sample Recruiting Application in Salesforce

How to disable button in Visualforce page?

Visualforce page:

 <apex:page controller="Sample" sidebar="false">
    <apex:pagemessages />
    <apex:form >
        <apex:commandButton value="Disable" disabled="{!disabl}" action="{!dis}"/>
    </apex:form>
</apex:page>


Apex Controller:

public class Sample
{
    public Boolean disabl {get;set;}
   
    public void dis()
    {
        disabl = true;
    }
}


Output:
After clicking the button

Facebook API

https://developers.facebook.com/

Check this...

Cheers!!!

Insufficient Privilege - You do not have the level of necessary access to perform this error

In order to troubleshoot this error, kindly follow the below steps
  1. Check the Object and Field level security.
  2. Check whether the Visualforce page is exposed to the respective profile.
  3. Check whether the role is restricting from doing required operation on records.
  4. Make sure that the version settings of Visualforce page and its controller/extension are same.

Force.com Toolkit for Facebook

Recently asked Salesforce interview questions

1. Explain "Mixed_DML_Operation" error.

2. Do Apex test methods persist data to the Salesforce.com data store?

3. Is it necessary to write Apex test classes for custom controllers?

4. Explain Apex heap limit?

5. Is it possible to bypass Apex governor limits?

6. Which governor limit you used to face frequently?

7. Explain the relationship between Account and Contact?

8. Briefly explain view state in Apex?

9. How to enable view state in development mode?

10. How to bulkify trigger?

Customer Portal supportable objects in Salesforce

  • Answers
  • Articles
  • Ideas
  • Home
  • Cases
  • Reports
  • Solutions
  • Web tabs
  • Entitlements
  • Custom objects
  • Service contracts
  • Chatter Answers
  • Documents from the Documents tab
  • Salesforce CRM Content tabs: Libraries, Content, and Subscriptions
Additionally, the Customer Portal allows
  • Accounts
  • Contacts

MIXED_DML_OPERATION error in Salesforce

You can easily run into this error if you are trying to perform DML on setup and non-setup objects in the same transaction.

Non-Setup objects are standard objects like Account or any custom object.

Setup objects are Group1, GroupMember, QueueSObject, User2, UserRole, UserTerritory, Territory, etc..

For example, you cannot insert an account and then insert a user or a group member in a single transaction.

Test methods allow for performing mixed DML operations between the sObjects listed earlier and other sObjects if the code that performs the DML operations is enclosed within System.runAs method blocks. This enables you, for example, to create a user with a role and other sObjects in the same test.

Apex Web Services and Callouts Document

Kindly visit the below link for Apex Web Services and Callouts

http://wiki.developerforce.com/page/Apex_Web_Services_and_Callouts

Too many DML statements: 1 out of 0 Error in Salesforce

In <apex:page> tag, if attribute "readonly" is true and if we try to execute DML statements(Insert, Update, Delete), then it shows Too many DML statements: 1 out of 0 Error in Salesforce.

So, in order to rectify this error, set readOnly = "false" or remove this attribute in <apex:page> tag.

Sample code:

<apex:page controller="Sample" sidebar="false" readOnly="false">

Cheers!!!

runAs Method in Salesforce

Generally, all Apex code runs in system mode, and the permissions and record sharing of the current user are not taken into account. The system method runAs enables you to write test methods that change either the user contexts to an existing user or a new user. When running as a user, all of that user's record sharing is then enforced. You can only use runAs in a test method. The original system context is started again after all runAs test methods complete.

The following items use the permissions granted by the user specified with runAs running as a specific user:
  • Dynamic Apex
  • Methods using or
  • Shared records
The original permissions are reset after runAs completes.
The runAs method ignores user license limits. You can create new users with runAs even if your organization has no additional user licenses.

Pagination with filter criteria using Apex in Salesforce

Sample Code:

Visualforce page:

<apex:page controller="Sample" sidebar="false">
<apex:form >
    <apex:pageBlock id="filter" title="Filter">
        <apex:pageBlockSection >
            <apex:pageblockSectionItem >
                <apex:outputLabel value="Name"/>
            </apex:pageblockSectionItem>
            <apex:pageblockSectionItem >
                <apex:inputText value="{!nam}" />
            </apex:pageblockSectionItem>   
        </apex:pageBlockSection>
        <apex:pageBlockSection columns="5" >     
            <apex:pageblockSectionItem >
                <apex:outputLabel value="Age"/>
            </apex:pageblockSectionItem>                     
            <apex:pageblockSectionItem >
                <apex:selectList multiselect="false" size="1" value="{!option}">
                    <apex:selectOption itemLabel="Greater than" itemValue=">"/>
                    <apex:selectOption itemLabel="Less than" itemValue="<"/>
                    <apex:selectOption itemLabel="Equal to" itemValue="="/>
                    <apex:selectOption itemLabel="between" itemValue="between"/>
                    <apex:actionSupport event="onchange" action="{!dispAge2}" reRender="filter"/>
                </apex:selectList>
            </apex:pageblockSectionItem>  
            <apex:pageBlockSectionItem >
                <apex:inputText value="{!age1}"/>
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem rendered="{!age2bool}">
                <apex:outputLabel value="And"/>
            </apex:pageBlockSectionItem>            
            <apex:pageBlockSectionItem rendered="{!age2bool}">
                <apex:inputText value="{!age2}"/>
            </apex:pageBlockSectionItem>                                       
        </apex:pageBlockSection>
        <apex:pageBlockButtons >
            <apex:commandButton value="Fetch" action="{!fetch}" reRender="pagination"/>
        </apex:pageBlockButtons>        
    </apex:pageBlock>
           
    <apex:pageBlock id="pagination" title="Member Details">
        <apex:pageblockTable value="{!memb}" var="m">
            <apex:column value="{!m.Name}"/>
            <apex:column value="{!m.Age__c}"/>          
        </apex:pageblockTable>
        <apex:pageblockButtons >
            <apex:commandButton value="<<" rerender="pagination" action="{!beginning}" disabled="{!prev}"/>
            <apex:commandButton value="<" rerender="pagination" action="{!previous}" disabled="{!prev}"/>
            <apex:commandButton value=">" rerender="pagination" action="{!next}" disabled="{!nxt}"/>
            <apex:commandButton value=">>" rerender="pagination" action="{!end}" disabled="{!nxt}"/>                                  
        </apex:pageblockButtons>
    </apex:pageBlock>   
</apex:form>
</apex:page>



Apex Controller:

public without sharing class PaginationWithFilter
{  
    public String soql;
        
    public String nam {get;set;}
    public Integer age1 {get;set;}        
    public Integer age2 {get;set;}
    public String option {get;set;}
    public Boolean age2bool {get;set;}  
   
    public Boolean fetchCalled;
  
    public integer totalRecs {get;set;}
    private integer index = 0;
    private integer blockSize = 5;      
  
    public PaginationWithFilter()
    {
        age2bool = false;  
        totalRecs = [select count() from Member__c];       
        fetchCalled = false;
    } 
  
    public void fetch()
    {         
        soql = 'SELECT Name, Age__c FROM Member__c';
        if(option == '>')
        {
        soql += ' WHERE Age__c > ' + String.ValueOf(age1);
        }
        else if(option == '<')
        {
        soql += ' WHERE Age__c < ' + String.ValueOf(age1);
        }
        else if(option == '=')
        {
        soql += ' WHERE Age__c = ' + String.ValueOf(age1);
        }
        else
        {
        soql += ' WHERE Age__c > ' + String.ValueOf(age1) + ' AND ' + 'Age__c < ' + String.ValueOf(age2);
        }
        if(nam != '')
        {
        soql += ' AND Name LIKE  \'%' + nam + '%\'';
        }      
       
        List<Member__c> tempMemb = Database.Query(soql);
        totalRecs = tempMemb.size();  
       
        soql += ' LIMIT ' + blockSize + ' OFFSET ' + index; 
       
        fetchCalled = true;                        
    }       
   
    public List<Member__c> getMemb()
    {      
        List<Member__c> membs;
        if(fetchCalled)
        {
            fetch();
        }  
        else
        {
            soql = 'SELECT Name, Age__c FROM Member__c LIMIT : blockSize OFFSET : index';
        }          
        membs = Database.Query(soql);       
        System.debug('Values are ' + membs);
        return membs;       
    }   
  
    public void dispAge2()
    {
        if(option == 'between')
        age2bool = true;
        else
        age2bool = false;
    }                 
  
    public void beginning()
    {
        index = 0;
    }
 
    public void previous()
    {
        index = index - blockSize;
    }
 
    public void next()
    {
        index = index + blockSize;
    }

    public void end()
    {
        index = totalrecs - math.mod(totalRecs,blockSize);
    }     
 
    public boolean getprev()
    {
        if(index == 0)
        return true;
        else
        return false;
    }
 
    public boolean getnxt()
    {
        if((index + blockSize) >= totalRecs)
        return true;
        else
        return false;
    }    
}


For demo, kindly visit,
http://infallibletechie-developer-edition.ap1.force.com/Site_Home_Page

Output: