function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ColinKenworthy1ColinKenworthy1 

Error occurred trying to load the template for preview: collection exceeds maximum size: 1001

I created a visualforce email template (and it works OK) just the preview on the template page does not show.

 

"Error occurred trying to load the template for preview: collection exceeds maximum size: 1001. Please try editing your markup to correct the problem."

 

Anyone know what the error is referring to?

I did not find anything searching for it.

Best Answer chosen by Admin (Salesforce Developers) 
jkucerajkucera

Typically in Apex these come when a list, map, set, or query returns more than 1000 records, which is the governor limit set.

 

Do you have the VF page calling any apex that might break this 1000 limit? 

All Answers

jkucerajkucera

Typically in Apex these come when a list, map, set, or query returns more than 1000 records, which is the governor limit set.

 

Do you have the VF page calling any apex that might break this 1000 limit? 

This was selected as the best answer
ColinKenworthy1ColinKenworthy1

The vf uses a component which provides a table of open Cases for the recipient Contact. The component receives the Contact Id and uses an apex controller (passing the Contact Id) to do the soql select of open Cases.

 

So in the template detail (not edit) page what is it trying to run that would pull back > 1000 rows. I thought it was just supposed to display an example email for (example) Sarah Sample?

 

I guess I could add 'LIMIT 1000' to the soql but I thought that was implicit in salesforce?

 

 

 

The plain text part of the email contains:

The requests below are still being investigated by Client Services. [ Raised ] - [ Case Number ] - [ Product Family ] - [ Product ] - [ Type ] - [ Sub Type ] - [ Owner ] - [ Status ] <apex:repeat var="cx" value="{!recipient.Cases}"> <apex:outputText rendered="{!cx.isClosed==false}"> [ {!cx.CreatedDate} ] - [ {!cx.CaseNumber} ] - [ {!cx.Product_Family__c} ] - [ {!cx.Product__c} ] - [ {!cx.Type} ] - [ {!cx.Sub_Type__c} ] - [ {!cx.Owner.Name} ] - [ {!cx.Status} ] </apex:outputText> </apex:repeat> We appreciate your patience and will address your requests as quickly as possible. Regards,

 

The apex controller for the component for the vf part of the email contains:

 

public List<Case> getTheOpenCases() { theOpenCases = new List<Case>(); //criteria for open cases for (Case c : [SELECT Id,CreatedDate,CaseNumber,Product_Family__c, Product__c,Type,Sub_Type__c,Owner.Name,Status FROM Case WHERE IsClosed = false AND ContactId = :thisContactId AND RecordTypeId = :MY_RECTYPE_ID ORDER BY CreatedDate]) { theOpenCases.add(c); } return theOpenCases; }

 

jkucerajkucera

The LIMIT 1000 isn't applied unless you do so explicitly like this:

 

public List<Case> getTheOpenCases() {
theOpenCases = new List<Case>();
//criteria for open cases
for (Case c : [SELECT Id,CreatedDate,CaseNumber,Product_Family__c,
Product__c,Type,Sub_Type__c,Owner.Name,Status
FROM Case
WHERE IsClosed = false
AND ContactId = :thisContactId
AND RecordTypeId = :MY_RECTYPE_ID
ORDER BY CreatedDate LIMIT 1000]) {
theOpenCases.add(c);
}
return theOpenCases;
}