We have a Screen Flow that basically creates quotes. In that flow, two Apex Actions are called: one that creates a QuoteDocument from a visualforce rendered as pdf:
PageReference pdf = Page.presupuestoPDF;
pdf.getParameters().put('id', presupuestos[0]);
QuoteDocument adjunto = new QuoteDocument();
adjunto.document = !Test.isRunningTest() ? pdf.getContent() : Blob.valueOf('test');
adjunto.quoteId = presupuestos[0]; //quote id list received as param
insert adjunto;
And then a second Apex Action that basically sends an email from a template, with some attachments, including that pdf:
for(QuoteDocument qd : quoteDocuments.values()){
attachment = new Messaging.EmailFileAttachment();
attachment.setFileName(qd.Name);
attachment.setBody(qd.Document);
attachment.setContentType('application/pdf'); //I tried adding this, but it doesn't solve anything
attachments.add(attachment);
}
EmailTemplate template = [SELECT Id FROM EmailTemplate WHERE Name = :'Presupuesto'];
Messaging.SingleEmailMessage emailMessage = Messaging.renderStoredEmailTemplate(template.Id, oppo.ContactId, oppo.Id);
emailMessage.setBccSender(true);
emailMessage.setFileAttachments(attachments);
List<Messaging.SendEmailResult> result = Messaging.sendEmail(new List<Messaging.SingleEmailMessage>{emailMessage});
So the problem is that, when using the screen flow normally, the email sends correctly BUT the pdf attached to the email is only 1.5kb and corrupt, can't preview or open it. But if I execute the screen flow from the debug section of the flow builder, the email is sent correctly and the PDF is NOT corrupted and I can preview and open it normally.
What is the difference between the execution context of the flow debugger and the normal execution context? What could I change in my flow to solve this?
EDIT:
When opening the generated pdf, this is what shows when opening with notepad:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<script>
function redirectOnLoad() {
if (this.SfdcApp && this.SfdcApp.projectOneNavigator) { SfdcApp.projectOneNavigator.handleRedirect('https://vc1687380243540.my.salesforce.com?ec=302&startURL=%2Fapex%2Fpresupuestopdf%3Finline%3D1%26id%3D0Q0Ho000001DiiUKAS'); } else
if (window.location.replace){
window.location.replace('https://vc1687380243540.my.salesforce.com?ec=302&startURL=%2Fapex%2Fpresupuestopdf%3Finline%3D1%26id%3D0Q0Ho000001DiiUKAS');
} else {
window.location.href ='https://vc1687380243540.my.salesforce.com?ec=302&startURL=%2Fapex%2Fpresupuestopdf%3Finline%3D1%26id%3D0Q0Ho000001DiiUKAS';
}
}
redirectOnLoad();
</script>
</head>
</html>
<!-- Body events -->
<script type="text/javascript">function bodyOnLoad(){if(window.PreferenceBits){window.PreferenceBits.prototype.csrfToken="null";};}function bodyOnBeforeUnload(){}function bodyOnFocus(){}function bodyOnUnload(){}</script>
</body>
</html>
<!--
...................................................................................................
...................................................................................................
...................................................................................................
...................................................................................................
-->