[Salesforce Update] The critical update named “PageReference getContent() and getContentAsPDF() Methods Treated as Callouts” was scheduled for auto-activation in Winter ’16. To allow for planning and implementing the solution, the auto-activation date has been postponed until Spring ’16.
Read more @ https://partners.salesforce.com/partnerAlert?id=a033000000GAPdDAAX
We use the GetContentAsPDF to generate PDF documents and attach them to the relevant record. This function is called in the following 2 scenarios:
- When a condition on a record is satisfied as it is updated. In this scenario, we call a future method and in the future method, a Apex callout is made to a REST service which generates the document and attaches to the record.
- A batch class runs once every day to find out the records which satisfy our criterias and if they do, we make a Apex Callout to the same Rest Service which generates the document and attaches to the record.
This all worked fine. But after the Spring 15 release, getContentAsPDF will be counted as a callout. We enabled the critical update in Sandbox (this update will be auto applied to production on 11th September). Once updated, the logic no longer works. We get an error called 'Callout Loop not allowed'. Makes sense because we are now doing another callout from the callout function.
Does anyone have an idea on how to solve this? We are trying different approaches here but none have worked.
Update [26Aug'15]: I got hold of a prerelease org with Winter'16 features enabled and wrote a simple code to
- Fire a trigger on Account Update
- Call a future method
- Do getContent in future method.
- Attach the document as attachment under Account
It worked fine and the attachment also had proper details. I tried the same code in our sandbox which had the critical update applied and the attachment generated was blank.
So basically, till Winter'16 changes are applied (sometime in October), there is no way to use getContent() or getContentAsPDF() batch apex or future class. Are there any alternatives? I have tried Post methods, future to post to future. None have worked.