Control Data Size
Visualforce pages have a 15-MB standard response limit, and smaller pages load faster
than larger pages. To minimize load times, limit the amount of data that each page
displays.
Filter Query Results
- Use filters to limit the data that Salesforce Object Query Language (SOQL) calls in and that Apex controllers return. For example, use AND statements in WHERE clauses. You can also remove null query results.
- When creating Apex controllers, use the with sharing keyword to retrieve only records that the user can access.
- Filter in SOQL first, then in Apex, and finally in Visualforce.
Use Pagination
- A page with unbounded data can cause longer load times, hit governor limits, and become unusable as the dataset grows. To prevent a list view from displaying unbounded data, implement pagination with a list controller. By default, a list controller returns 20 records per page, but you can configure list views to display up to 100 records at a time. To control the number of records each page displays, use a controller extension to set the pageSize.
- Use the SOQL OFFSET clause to write logic that paginates to a specific subset of results within SOQL.