The community users can render the VF page as a PDF and record this action in the custom object as a log record when they click the button to generate the PDF from the LWC on the community page (digital experience page).
When a user clicks the button the LWC opens another tab in the browser and a PDF is generated. However, the problem is that two records are created on the custom object LogPDF__c. Also, when I debug the issue I can see two separate debug logs for a user action.
The LWC has a button:
<button onclick={generatePDF}>
Generate PDF
</button>
the function on LWC
generatePDF() {
const urlPDF = 'https://power-business-3760-dev-ed.scratch.my.site.com/apex/testVFPageRenderAsPDF';
console.log('const url pdf ', urlPDF);
window.open(urlPDF, '_blank');
}
Visual force page
<apex:page controller="TestVFPageRenderAsPDFController" renderAs="pdf" action="{!createVFPDFLog}">
<!-- Begin Default Content REMOVE THIS -->
<h1>Congratulations</h1>
This is your new Page
<!-- End Default Content REMOVE THIS -->
</apex:page>
Controller for Visual Force page
public with sharing class TestVFPageRenderAsPDFController {
public TestVFPageRenderAsPDFController() {
System.debug('xxx constructor');
}
public void createVFPDFLog() {
System.debug('xxx createVFPDFLog');
LogPDF__c logPDF = new LogPDF__c();
insert logPDF;
}
}
I have checked the debug logs, and the debug logs are separate transactions. Two debugs logs created
I have checked the problem in different browsers and the issue is only seen on the Edge browser. In Chrome the debug logs and LogPDF record is created one time.
I checked the settings of the browser and couldn't find anything useful and related to my issue.
I suspect it might be something related with calling that VF page from the community page. When I created the LWC with a button and called that from the salesforce org, it generated the PDF and created the log record only one time.
I would like to have only one log record created on the LogPDF custom object per one Generate PDF pressed button.