-1

i create headless quick action. My action attach pdf with name 'Test Attachment for PDF'. I want name pdf file from Invoice_number__c - its a custom field (auto_number) on opportunity object. how i can do this?

7
  • Hello Bogdan. Do you use aura component or LWC? Also I would suggest to pass the recordId to the controller method Feb 2, 2022 at 8:20
  • Hello Alin, thank you for your reply. I create visual force page with custom controller. I use Lightning Web Component in headless quick action. Can u say me how i can do it in recordId? I add headless quick action for my quastion
    – Bogdan
    Feb 2, 2022 at 8:53
  • Honestly it's hard to really find an answer, even when seeing your full code. I can see you have a variable declared as public Opportunity opportunity {get; set;}. Theoretically that should be what you use to display data on the front-end. Also in your VF page button that triggers the action you should pass the opportunity.Id as a parameter so that you have access to it in the savePDF() method. And also I don't understand why you didn't used the Visualforce renderAs="pdf" functionality and you have to mix it with LWC. Feb 3, 2022 at 6:30
  • @AlinParaschiv thanks, I used headless quick action (LWC) because I need to generate a pdf file and bind it to an object. If I do just RenderPdf, even though I have it written in code, but if I remove the LWC, I can only view my VisualForce page without linking the pdf document to the Opportunity object.
    – Bogdan
    Feb 3, 2022 at 8:28
  • you can do it with VF as well, but fine, can you also add the code for your VF page? Feb 3, 2022 at 9:27

1 Answer 1

1

Try the following. Edit your generateInvoice.js-meta.xml to include the following target:

<targets>
    <target>lightning__AppPage</target>
<targets>

Save and deploy to SF.

Create a new Lightning Page in Lightning App Builder and copy the api(you will need it later). I'm guessing it's going to be generate_Invoice

Create a new detail page button with the following url

/lightning/n/generate_Invoice?c__oppId={!Opportunity.Id}

Note: you have to add the c__ prefix to the parameter of oppId in order to be able to pass it. Also generate_Invoice is the api from the Lightning page.

In your lwc add the following pieces of code in order to retrieve the oppId:

Import the page reference

import { CurrentPageReference} from 'lightning/navigation';

Remove @api from recordId

recordId;//remove @api decorator

Add the following wire function that retrieves the oppId parameter from your URL

@wire(CurrentPageReference)
getStateParameters(currentPageReference) {
   if (currentPageReference) {
      this.recordId = currentPageReference.state.c__oppId;
   }
}
5
  • yes, no need to add the prefix there. I wanted to emphasize that you need to add it in the button url and here: this.recordId = currentPageReference.state.c__oppId; Feb 3, 2022 at 13:11
  • it's fine under the recordId variable. What that error says is that you have not imported the wire decorator. Just add wire in your first import on the page import { LightningElement, api, wire } from 'lwc'; Feb 3, 2022 at 13:24
  • ah yes. My bad, I forgot to mention one part. I will edit the original response to include that too Feb 3, 2022 at 14:17
  • @Bogdan any luck? Feb 3, 2022 at 15:30
  • Let us continue this discussion in chat.
    – Bogdan
    Feb 3, 2022 at 16:02

You must log in to answer this question.

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