2

I have a Visualforce page being called in LEX via a button/action on the record. The page is straightforward as shown below:

<apex:page id="CTISGenerateVF" lightningStylesheets="true" controller="CTISGenerateController" showHeader="true" sidebar="true" action="{!generateDocuments}">
   <apex:form id="form1">
    <apex:pageBlock >
        <apex:pageMessages />
        <apex:commandButton value="Back" action="{!backToRecord}" />
    </apex:pageBlock>
</apex:form>

The controller then calls a couple of other VF pages that generates a PDF and CSV file. Here's a snippet of the controller code:

    public PageReference generateDocuments() {
    PageReference pageRef;
    List<ContentVersion> listCV = new List<ContentVersion>();
    List<ContentDocumentLink> listCDL = new List<ContentDocumentLink>();

    try {
        String dateTimeStamp = System.now().format('ddMMyyyy hh:mm:ss').replace(' ', '_').replace(':', '');

        // Generate CSV file
        PageReference pageRefCSV = new PageReference('/apex/CTISGenerateCSVVF?id=' + this.ctisId);
        Blob csvBody = (!test.isRunningTest() ? pageRefCSV.getContent() : Blob.valueOf('test'));
        ContentVersion cvCSV = new ContentVersion();
        cvCSV.VersionData = csvBody;
        cvCSV.Title = 'FoneZone_' + dateTimeStamp + '.csv';
        cvCSV.PathOnClient = 'FoneZone_' + dateTimeStamp + '.csv';
        listCV.add(cvCSV);

        // Generate PDF file
        PageReference pageRefPDF = new PageReference('/apex/CTISGeneratePDFVF?id=' + this.ctisId);
        Blob pdfBody = (!test.isRunningTest() ? pageRefPDF.getContentAsPDF() : blob.valueOf('test'));
        ContentVersion cvPDF = new ContentVersion();
        cvPDF.VersionData = pdfBody;
        cvPDF.Title = 'FoneZone_' + dateTimeStamp + '.pdf';
        cvPDF.PathOnClient = 'FoneZone_' + dateTimeStamp + '.pdf';
        listCV.add(cvPDF);

        // Insert ContentVersion list
        insert listCV;

I am having an error when the context shifts to the VF pages, getting an Internal Server Error with the following message in the Console:

Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://xxx.lightning.force.com') does not match the recipient window's origin ('https://XXX.visual.force.com').

Not sure how to go about next - are there any other options to make this work other than rewriting the VF pages into Lightning? Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.