When attempting to create a quote and then generate a PDF using the quote in the same context, I get one of the dwarf errors:
Line: -1, Column: -1 ORA-20001: ORA-06512: at "HAPPY.CACCESS", line 1492ORA-06512: at "HAPPY.CACCESS", line 2995ORA-06512: at "HAPPY.CACCESS", line 2768ORA-06512: at line 1SQLException while executing plsql statement: {call cAccess.check_entity_access_proc_ncu(?,?,?,?,?,?)}(EXCLUDED, EXCLUDED, 0Q00v000000CaYh, EXCLUDED, true, false)
(So far I've seen Happy and Dopey but they both reference CACCESS).
Code to reproduce (Execute Anonymous):
Opportunity openOpp = [
SELECT Id
FROM Opportunity
WHERE IsClosed = false
LIMIT 1
][0];
Quote newQuote = new Quote(
OpportunityId = openOpp.Id,
Name = 'doesn\'t matter'
);
insert newQuote;
// You can't query this object so you have to hard code a quote template ID
// We use a custom setting
Id templateId = '';
String url = '/quote/quoteTemplateDataViewer.apexp?id=' +
newQuote.Id + '&summlid=' + templateId;
PageReference contentSource = new PageReference(url);
Blob pdf = contentSource.getContentAsPDF();
If you run this with an existing quote instead of a new one, there are no errors.
I believe this is because PageReference.getContentAsPDF(); is treated as a callout and you cannot make a callout while you have uncommitted work.
The only solution I can think of is to split this into two separate transactions. This poses an issue for me as I'm already doing my work in a batch class (which means I can't use @future methods). I believe this means my only option is to use a queueable.
Can anyone think of any solution other than using a queueable? My concern is that there are limits to queueables and we're writing this as a batch as we expect a high volume of records to process.
Use Case: We are generating renewal opps/quotes automatically and sending out renewal emails with quote pdfs attached (we're also attaching the PDFs to the quotes for record keeping).
Update
Took me a bit of digging but I found a similar question. I don't believe their solution will work for me though.