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
Chie MenChie Men 

How to open generated PDF file to a browser instead of making it as an attachment?

Hi,
I have a "Generate PDF" button in my Asset detail page.  I was able to generate a PDF file but instead of making it as an attachment to the Asset detail page. Here is the code I get online to generate a PDF file:

Blob pageData; //variable to hold binary PDF data.
        if(!Test.isRunningTest()){ // for code coverage        
            pageData = thePage.getContentAsPDF();
        } else {
             pageData = Blob.valueOf('This is a test.');
         }
        
         //create attachment
        Attachment att = new Attachment(
            ParentId=recordId,
            Body=pageData,
            Name= lname + 'Asset_' + DateTime.now().formatLong() + '.pdf'
         ); 
         insert att;

Instead of attaching the pdf file, I want it to open in a new browser tab.

Thank you.