一、page页面遇到需要检索大量数据的处理方式需要时会用Readonly
通常,对单个Visualforce页面请求的查询可能无法检索超过50,000行。 在Read only模式下,此限制将放宽允许查询最多1,000,000行。
<apex:page controller="SummaryStatsController" readOnly="true">
<p>Here is a statistic: {!veryLargeSummaryStat}</p>
</apex:page>
public class SummaryStatsController {
public Integer getVeryLargeSummaryStat() {
Integer closedOpportunityStats =
[SELECT COUNT() FROM Opportunity WHERE Opportunity.IsClosed = true];
return closedOpportunityStats;
}
}
同样也会让组件的限制增加,如<apex:dataTable>, <apex:dataList>, and <apex:repeat>. 会从1000增加到10000;
<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>
public class MerchandiseController {
public List<Merchandise__c> getAllMerchandise() {
List<Merchandise__c> theMerchandise =
[SELECT Name, Price__c FROM Merchandise__c LIMIT 10000];
return(theMerchandise);
}
}
二、Apex 中的Readonly
Visualforce控制器方法可以使用Apex ReadOnly注释,但有一些重要的限制,即使页面本身不是在只读模式下。
带有@ReadOnly注释的Visualforce控制器方法会自动利用只读模式。
对于Visualforce控制器方法,只读方法也必须具有@RemoteAction注释。 关于@RemoteAction可以参考上篇文章:https://i.cnblogs.com/EditPosts.aspx?postid=9682154
@RemoteAction注释要求方法为:
<div id="totalAccounts"></div>
<script>
Visualforce.remoting.Manager.invokeAction(
'{!$RemoteAction.YOUR_CONTROLLER_NAME.getRemoteTotalAccounts}',
function(result){
document.getElementById('totalAccounts').innerHTML = result;
}
);
</script>
@RemoteAction
@readOnly
public static Integer getRemoteTotalAccounts() {
return [Select count() FROM Account];
}
这个例子并未真实测试过。总之,readonly是可以扩大之前limit的限制