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>

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];

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

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.


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. 

No comments:

Post a Comment