anusha(salesforce developer)

Read-only Mode for VisualForce page and ReadOnly Annotation for Controller to Lift Salesforce Governer Limits.

Using SOQL queries we can retrieve Maximum of 50000 records(Governor Limits) and  Visualforce iteration components, such as <apex:pageBlockTable> and <apex:repeat>, are limited to a maximum of 1,000 items in the collection they iterate over.

Sometimes Visualforce pages may need to work with or display larger sets of data, but not need to make modifications to that data; for example, if you are providing custom reporting and analytics.  
In this senorio we can go for Read-Only mode for entire page.Readonly attribute takes  Boolean value(true) to enables read-only mode for a Visualforce page. In read-only mode, a page may not execute any DML operations, but the limit on the number of records retrieved is relaxed from 50,000 to 1 million rows. It also increases the number of items in a collection that can be handled by iteration components, from 1,000 to 10,000.

** ReadOnly attribute default value is False.

@ReadOnly  Annotation for Controller Methods.

          we  can also use  the Apex Readonly annotation, even if the page itself isn’t in read-only mode


Visualforce controller methods with the @ReadOnly annotation automatically take advantage of read-only mode(retrieve a larger collection of records).Those method should also have @remote action annotation and below access specifiers
  • Either global or public
  • static

Enabling read-only mode by using the @ReadOnly annotation must be done on the top level method call. If the top level method call doesn’t have the@ReadOnly annotation, the normal restrictions on maximum queried rows are enforced for the entire request, even if secondary methods are annotated with @ReadOnly.

ReadOnly Mode Blocks you from performing the following operations within the request
  *    DML operations
  *    calls to System.schedule,
  *    calls to methods annotated with @future
 *  sending emails.

The @ReadOnly annotation is available for Web services and the Schedulable interface. To use the @ReadOnlyannotation, the top level request must be in the schedule execution or the Web service invocation. For example, if aVisualforce page calls a Web service that contains the @ReadOnly annotation, the request fails because Visualforce is the top level request, not the Web service .

No comments:

Post a Comment