I am facing the problem that I cannot run the code because there are no triggers to run it. I need the pdf file to be previewed in the module window. Tried through conectedCallback and wire, it didn't work. Here is my code.

export default class ProposalPreviewPDF extends LightningElement {
@api parameter1;//taking from parent html
@api parameter2;

@wire (generateProposal, {proposalId: '$parameter1'})
        if (result) {
            this.parameter2 = '/sfc/servlet.shepherd/document/download/' + result;
}}//paremeter2 I am transferring to htlm file


public with sharing class proposalPreviewPDFController {

public static String generateProposal(Id proposalId)
    System.debug('here' + proposalId);
    Blob body;
    PageReference pageRef = new PageReference('/apex/TemplateForProposal');  
    pageRef.getParameters().put('proposalId', proposalId );// - параметр будет передан в контроллер VF страницы 

        body = pageRef.getContentAsPDF();
        body = blob.valueOf('Test');

    ContentVersion cont = new ContentVersion();
    cont.Title = 'Title for this contentVersion';
    cont.PathOnClient = 'file.pdf';
    cont.VersionData = body;
    cont.Origin = 'H';

    insert cont; 

    Id conDocId = [SELECT ContentDocumentId FROM ContentVersion WHERE Id =:cont.Id].ContentDocumentId;

    ContentDocumentLink cdl = new ContentDocumentLink();
    cdl.ContentDocumentId = conDocId;
    cdl.LinkedEntityId = proposalId;
    cdl.ShareType = 'V';
    insert cdl; 

    return cdl.ContentDocumentId;


Сan someone help?


1 Answer 1


You need to be addressing the data portion of the response. Additionally, since you are creating records in your APEX call, you cannot use @wired (why you are getting the DML Limit error of 1 record). So what we needed to do is create a getter and setter for the @api decorator... and call the apex method in the setter.

import { LightningElement, api } from "lwc";
import generateProposal from @salesforce/apex/proposalPreviewPDFController.generateProposal;

export default class ProposalPreviewPDF extends LightningElement{
    _parameter1;  //hold current value to see if you should recall apex
    error; //you should handle the error state. 

    get parameter1() {
        return this._parameter1;
    set parameter1(value) {
        if(this._parameter1 !== value) {
            this._parameter1 = value;
            generateProposal({ proposalId: value })
                .then((result) => {
                    this.parameter2 = '/sfc/servlet.shepherd/document/download/' + result;
                    this.error = undefined;
                .catch((error) => {
                    this.parameter2 = undefined;
                    this.error = error;

Looking at the apex method, it needs to be decorated with @AuraEnabled, but not @AuraEnabled(cacheable = true) //don't use cacheable = true if you are updating records, or you will get a DML Limit Error

public with sharing class proposalPreviewPDFController {

public static String generateProposal(Id proposalId)
  • Comments are not for extended discussion; this conversation has been moved to chat.
    – David Reed
    Nov 10, 2021 at 14:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .