There are quite a number of posts I went through that talk about 'Apex CPU Time limit exceeded' issue. I am looking for some advice on how to work around this problem with my situation in mind.
We have a custom VF page with a custom controller that does a LOT of computations and displays a page/PDF with 6 pages of complex data based on ONE record/entity. This part works fine.
Now I need to generate ONE PDF for multiple records (stacked). So, for example, if the user chooses 5 records, the PDF must contain 30 pages of data.
To accomplish this, all I did was to write a for-loop on the method that works on one for as many records as selected. This is where I am hitting 'Apex CPU Time limit exceeded' issue.
The code is fairly complex (5 SOQL statements but a lot of loops, 7000 lines) and although we put in effort to optimize it, re-optimizing it could be a herculean task which won't be approved. Even if we were successful with a little more optimization, there is no guarantee that something that works for 5 records (= 30 pages) now wouldn't fail for 7 (= 42 pages).
Salesforce support won't increase our limits.
I understand that the CPU limit on asynchronous transactions is 6 times higher than synchronous. So I followed this blog post but it still doesn't work for us. Reason: Although I have a REST Consumer method that is declared as @future (CPU limit = 60,000 ms); it calls a global RESTful web service setup in Salesforce (@HttpPost) that is responsible for generating the PDF, and it appears like the latter is still slapped with 10,000 ms of CPU time! Neither the @future methods nor the Batch jobs support getContentAsPDF() method.
So: I would like to utilize the 60,000 ms CPU time in an asynchronous transaction to generate a massive VF PDF and email it out to a user. What are the possible ways to accomplish that? I am really out of ideas.
Thanks in advance.