0

I create a very simple query to display the result at visualforce and render as pdf to store the pdf in an account. Unfortunately I ran always into Collection size 1.079 exceeds maximum size of 1.000 and I don't know how can I avoid this problem.

I found this solution, I edited my code but I still run into the error.

QUERY

public with sharing class FDB_Reporting {
    
    public List<FDB_Aktivit_t__c> FDBList {get; private set;}
    public Integer c1 {get; set;}
    public Integer c2 {get; set;}
    public Integer c3 {get; set;}
    public Integer c4 {get; set;}
    public Integer c5 {get; set;}
    public Date FirstDayOfLastMonth {get; set;}
    public Date LastDayOfLastMonth {get; set;}
    
    public FDB_Reporting() {
        
        FirstDayOfLastMonth = System.today().toStartOfMonth().addMonths(-1);
        LastDayOfLastMonth = System.today().toStartOfMonth().addDays(-1);
               
        FDBList = [SELECT Name, Account__c FROM FDB_Aktivit_t__c WHERE createdDate >= :FirstDayOfLastMonth AND createdDate <= :LastDayOfLastMonth];
        c1= [SELECT COUNT() FROM FDB_Aktivit_t__c WHERE contactassign__c = '1' AND createdDate >= :FirstDayOfLastMonth AND createdDate <= :LastDayOfLastMonth];
        c2= [SELECT COUNT() FROM FDB_Aktivit_t__c WHERE contactassign__c = '2' AND createdDate >= :FirstDayOfLastMonth AND createdDate <= :LastDayOfLastMonth];
        c3= [SELECT COUNT() FROM FDB_Aktivit_t__c WHERE contactassign__c = '3' AND createdDate >= :FirstDayOfLastMonth AND createdDate <= :LastDayOfLastMonth];
        c4= [SELECT COUNT() FROM FDB_Aktivit_t__c WHERE contactassign__c = '4' AND createdDate >= :FirstDayOfLastMonth AND createdDate <= :LastDayOfLastMonth];
        c5= [SELECT COUNT() FROM FDB_Aktivit_t__c WHERE contactassign__c = '5' AND createdDate >= :FirstDayOfLastMonth AND createdDate <= :LastDayOfLastMonth];
    }
    
}

CLASS to save the report

public without sharing class FDB_Export_Reports{
    
    @InvocableMethod(Label = 'create FDB Reports' description='')  
    
    public static void FDB_Reports_PDF() {
        
        PageReference page = Page.FDB_Reporting;
        
        Blob contentBlob = !Test.isRunningTest() ? page.getContentAsPDF() : Blob.valueOf('Hardcoded sample text for Test class');
        
        ContentVersion cv = new ContentVersion();
        cv.VersionData = contentBlob;
        cv.Title =  System.today().year() + '_' + System.today().month() + '_FDB_Alle_Aktivitaeten';
        cv.PathOnClient =  System.today().year() + '_' + System.today().month() + '_FDB_Alle_Aktivitaeten.pdf';
        insert cv;                
        cv = [SELECT Id, ContentDocumentId FROM ContentVersion WHERE Id = :cv.Id LIMIT 1];
        
        ContentDocumentLink cdl = new ContentDocumentLink();
        cdl.ContentDocumentId = cv.ContentDocumentId;
        cdl.ShareType = 'I';
        cdl.LinkedEntityId = '001b000000Zps12AAB';
        insert cdl;
    }   
}

VISUAL FORCE

<apex:page controller="FDB_Reporting" renderAs="pdf" applyBodyTag="false" applyHtmlTag="false" showheader="false">
   
    <html>
        <head>
            <style>
                table { page-break-inside:auto; 
                        border-collapse: collapse;
                        border: 1px solid;
                      }
                tr    { page-break-inside:avoid; 
                        page-break-after:auto; 
                        border: 1px solid;
                      }    
                th    { background-color: #33C4FF; 
                        border-color: black;
                        
                        font-weight: bold; 
                        border: 1px solid;
                      }
                td    { font-size: 9px; 
                        border: 1px solid;
                      }
                @page { size: A4 landscape;
                      }              
            </style>   
        </head>
        


        <center>
            <table style="font-family: sans-serif; font-size: 9px; border: 1px solid">    
                <tr>
                    <th>Name/Id</th>
                    <th>Account</th> 
                </tr>
                
                <apex:repeat value="{!FDBList}" var="text">          
                    <tr>
                        <td> {!text.Name}</td>
                        <td> {!text.Account__c}</td>                
                    </tr>         
                </apex:repeat>       
            </table>
        </center>    
        
    </html>    
</apex:page>
1
  • 3
    In the solution you've provided people are using Map instead of List. In your example you are still using List, so how come you've edited your code to follow their solution? Commented Apr 4, 2022 at 14:01

1 Answer 1

7

Adding readOnly="true" to the Visualforce page should fix your problem as explained in Setting Read-Only Mode for an Entire Page.

Note that this will raise the limit from 1,000 to 10,000 so you will still eventually run into a limit. So best to change the design: who is ever going to want to look at 1,000 or 10,000 rows of output anyway?

1
  • 2
    who is ever going to want to look at 1,000 or 10,000 rows of output anyway? this x1079 :p . The goal is generally to find a signal in the data. If you have 1000+ records, most of them are going to be uninteresting "noise" (that, or something has gone horribly wrong). Defining what the "signal" is and calling attention to it is where the value is.
    – Derek F
    Commented Apr 4, 2022 at 14:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .