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
Flight PlanFlight Plan 

PageReference getContent() and getContentAsPDF() Methods Behave as Callouts

As per Summer release 15, if someone calling this method will be treated as call out, Does it means that it has timeout of 2 minutes ?
What if customer using getContentAsPDF() method to generate the PDF , Did they get any impact (If they are generating large PDF's)?
NagaNaga (Salesforce Developers) 
Hi Flight,

This critical update changes the way calls made to the PageReference methods getContent() and getContentAsPDF() are treated and improves the semantics of the transaction for the calling page.
A PageReference is a reference to an instantiation of a Visualforce page. The getContent() and getContentAsPDF() instance methods return the content of a rendered page as HTML and PDF, respectively. With this update, calls made to these methods behave as callouts, and the calls are tracked against the limits of the calling transaction.

Best Regards
Naga Kiran
SFDC HedgehogSFDC Hedgehog
Just FYI:
I have code which creates a csv file from a report and emails the CSV to users.
This code is in the form of a VF component that has a page controller that uses the getContent function.  
It basically looks like this;
 
public void executeRpt() {
        String requestURL;
        requestURL = '/00OW0000000FpAL?csv=1&exp=1&enc=UTF-8';
        strCSV = new PageReference(requestURL).getContent().toString();
    }

This code will not work with this update.  
There was no governor limit warning or any error whatsoever -
it just simply would not work until I deactivated the change and then it worked fine..

I opened a case with Salesforce a few weeks ago and it's still open but it has been escalated by SFDC.

I would advise everyone to test before enabling this critical update.  
Beware.
 
Douglas TrasterDouglas Traster
Hedge;

We are running into the same issue.  Is there any documentation on what should be done?  There doesn't seem to be any fixes to the problem other than not using the getContent() or getContentAsPDF().  

I get the following error:
Error is in expression '{!submitHavePricing}' in component <apex:commandButton> in page formpricingsummarypg: Class.EmailFormWithAttachments.SendPricingFormEmail: line 50, column 1
Class.FormPricingSummaryCls.SubmitHavePricing: line 2226, column 1

The code at line 50 is :
      // Take the PDF content
        Blob b;
        if (Test.isRunningTest())
            b = Blob.valueOf('Test');
        else
            b = pdf.getContent();

and Line 2226 is 

 public PageReference SubmitHavePricing() {
        PageReference pr = null;
        if (Submit(false)) {
            pageController.getRecord();
            pr = Page.OpportunityForms;
            pr.getParameters().put( 'id', opp.Id );
            pr.setredirect(true);
            EmailFormWithAttachments.SendPricingFormEmail(f.id, false);

Basically, the 2226 is just calling the PDF to run when you hit submit.  

If I turn off the critical update it works.  
 
280z280z
This is also causing problems for me.  Has anyone found a workaround yet? 
SFDC HedgehogSFDC Hedgehog
280z:

If the highlighted critical update is deactivated, the problem seems to go away;

User-added image

I opened a case with SFDC on this, but I don't think it's fixed yet. 
 
280z280z
Yeah, the problem goes away if the critical update is deactivated.  But at some point Salesforce is going to activate it.  Originally that was going to be forced on us on Sept 11, but I just found out that it'll be delayed until Spring '16: https://help.salesforce.com/HTViewSolution?id=000228476&language=en_US

Still need to find a workaround.
SFDC HedgehogSFDC Hedgehog
Hi 280z

As a Premier Support customer, I was told my issue (in my post above) will be fixed, but in the meantime to disable the critical update.
Unfortunately, turning it off affects FinancialForce - so I'm stuck too.

Supposedly (from my SFDC rep) he said these issues will be resolved when the critical update is available -  I guess we'll have to wait and see :-/

I find it very hard to believe that SFDC will let  flagship features like  getContent() getContentAsPDF() have such a crippling defect.
 
280z280z
Has someone come up with a valid workaround for this, so that we can continue to use getContent()?
SFDC HedgehogSFDC Hedgehog
Hi 280z

I cobbled together a solution to my immediate problem.
I was using getContent() to forward a report in CSV format and using getContent() to format the report into a CSV.

I got around it with a VF component that builds dynamic VF.

The VF email template:
<messaging:emailTemplate subject="Excel Data Export of Edgecast Reports" recipientType="User" >
<messaging:plainTextEmailBody >

Hi,

please find attached the report(s) you have requested...

Kind regards,
{!$Organization.Name}
</messaging:plainTextEmailBody>
 
 <!--    D O E S N ' T   W O R K   A N Y M OR E !-->
 <!--messaging:attachment filename="VESOpportunity.csv"!-->
 <!--c:ReportOpportunityExportController xstrRptname="00O50000004Tisp"/!-->
 <!--/messaging:attachment!-->

 <!-- U S E   D Y N A M I C    R E P O R T    B U I L D E R   N O W !--
 <messaging:attachment filename="LeadDetail-InboundNew.HTML">
 <c:ReportOpportunityExportController xstrRptname="00O4B000000JUKT"/>
 </messaging:attachment>
 
</messaging:emailTemplate>
The ReportOpportunityExportController component;
apex:component controller="SyncReportController" access="global">
<apex:attribute name="xstrRptname" description="report ID" type="String" assignTo="{!reportId}"/>
<!-- apex:outputText value="{!ReportResults}" escape="false"/ !-->
  <style>
      table.reportResults {
          width: 100%;
      }
  </style>
  <apex:outputPanel id="reportResults" layout="block">
      <apex:outputPanel >
         <table class="reportResults">
           <thead>
               <apex:repeat value="{!reportResults.reportMetadata.detailColumns}" var="colName">
                   <th><apex:outputText value="{!reportResults.reportExtendedMetadata.detailColumnInfo[colName].label}"/></th>
               </apex:repeat>
           </thead>

           <tbody>
               <apex:repeat value="{!reportResults.factMap['T!T'].rows}" var="row" rows="999">
                   <tr>
                       <apex:repeat value="{!row.dataCells}" var="cell">
                           <td><apex:outputText value="{!cell.label}"/></td>
                       </apex:repeat>
                   </tr>
               </apex:repeat>
           </tbody>
         </table>
      </apex:outputPanel>
  </apex:outputPanel>

</apex:component>

The component controller;
public with sharing class SyncReportController {

    public Id reportId { get; set; }
    public Id instanceId { get; set; }
    public Boolean reportIsRunning { get; set; }
    private transient Reports.ReportResults reportResults;

    public SyncReportController() {
        }

    public void setReportId(String theReport) {
        reportId = theReport;
        }

    public PageReference runReport() {
        reportResults = Reports.ReportManager.runReport(reportId, true);

        return null;
    }

    public Reports.ReportResults getReportResults() {
        reportResults = Reports.ReportManager.runReport(reportId, true);
        return reportResults;
    }
}

The limitation is obvious -- if my report runs past 1000 lines the whole thing fails....
I could get around this by getting away from using the <apex:repeat>, but that's not possible with this solution.
Also, if there was some way to put "readonly=true" in the message template, that would increase my limit to 10,000 rows - which would be like pulling a nail out of my head, but the message:emailtemplate tag doesn't support this, so I'm stuck......

]
In the meantime, I'm constraining the report and just adding more and more reports to the email template.

I don't think this will work with people that require rendering into a PDF format, but I'm posting in case someone might be able to use it.




 
Michael PaulsonMichael Paulson
I'm getting some issues where my code works fine and as expected until I use getContent (or getContentAsPDF). Have you heard back from Salesforce on a potential solution to this?

Edited to add - It works fine if I rerender my page prior to hitting the getContent line, but I would rather not do this as it would just require another unnccessary button click.