You need to sign in to do that
Don't have an account?
Oscar Fernando De la Cruz
How to use id from Record Contact?
Hi everyone, I'm new on LWC . and I'm doing this example to generate a PDF https://santanuboral.blogspot.com/2020/10/lwc-generate-pdf.html
everything works fine but now Im trying to save the PDF to the correspondet contact depending on the ID, any idea of how I can do that? this is my code as we can see Im hard coding the id
public with sharing class DisplayRichTextHelper {
@AuraEnabled
public static Attachment generatePDF(String txtValue){
Pagereference pg = Page.renderAsPDF;
pg.getParameters().put('displayText', txtValue);
Contact con = new Contact(Id='0035f000008RNWCAA4');
Attachment objAttachment = new Attachment();
objAttachment.Name = 'J2S.pdf';
objAttachment.ParentId = con.Id;
objAttachment.Body = pg.getContentaspdf();
objAttachment.IsPrivate = false;
insert objAttachment;
return objAttachment;
}
}
And i want to change for some like this:
ApexPages.currentPage().getParameters().get('id');
everything works fine but now Im trying to save the PDF to the correspondet contact depending on the ID, any idea of how I can do that? this is my code as we can see Im hard coding the id
public with sharing class DisplayRichTextHelper {
@AuraEnabled
public static Attachment generatePDF(String txtValue){
Pagereference pg = Page.renderAsPDF;
pg.getParameters().put('displayText', txtValue);
Contact con = new Contact(Id='0035f000008RNWCAA4');
Attachment objAttachment = new Attachment();
objAttachment.Name = 'J2S.pdf';
objAttachment.ParentId = con.Id;
objAttachment.Body = pg.getContentaspdf();
objAttachment.IsPrivate = false;
insert objAttachment;
return objAttachment;
}
}
And i want to change for some like this:
ApexPages.currentPage().getParameters().get('id');
I hope you are using this LWC Component in Contact Record Page.
Please add the below changes in your code.
Apex Class:
LWC JS:
1. Add the api in import...
2. Declare the @api recordId;
3. Chnage in generatePDF({txtValue: editor.value , contactId : this.recordId })
In XML File:
Thanks,
Maharajan.C
All Answers
I hope you are using this LWC Component in Contact Record Page.
Please add the below changes in your code.
Apex Class:
LWC JS:
1. Add the api in import...
2. Declare the @api recordId;
3. Chnage in generatePDF({txtValue: editor.value , contactId : this.recordId })
In XML File:
Thanks,
Maharajan.C
I found this article on How to use id from Record Contact? quite useful, especially as someone like me, prettypaula (https://prettypaula.com/), who often needs to manage contact information efficiently. The step-by-step instructions provided clear guidance, making it easy to understand and implement. Thanks for sharing this helpful resource!