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'})
proposals(result){
if (result) {
this.parameter2 = '/sfc/servlet.shepherd/document/download/' + result;
///sfc/servlet.shepherd/document/download/'
}
}}//paremeter2 I am transferring to htlm file
/------------------------------------------------------------------/
public with sharing class proposalPreviewPDFController {
@AuraEnabled(cacheable=false)
public static String generateProposal(Id proposalId)
{
System.debug('here' + proposalId);
Blob body;
PageReference pageRef = new PageReference('/apex/TemplateForProposal');
pageRef.getParameters().put('proposalId', proposalId );// - параметр будет передан в контроллер VF страницы
if(!Test.isRunningTest())
{
body = pageRef.getContentAsPDF();
}
else
{
body = blob.valueOf('Test');
}
System.debug(body);
ContentVersion cont = new ContentVersion();
cont.Title = 'Title for this contentVersion';
cont.PathOnClient = 'file.pdf';
cont.VersionData = body;
cont.Origin = 'H';
insert cont;
System.debug(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;
System.debug(cdl.Id);
return cdl.ContentDocumentId;
}
}
Сan someone help?