You need to sign in to do that
Don't have an account?
David89
How to create a pdf?
Hi all,
I need to create a pdf (with the lead information) when a lead is created, this pdf is saved as document.
I wrote an apex class with an invocable method which fire in a process builder after
a lead creation, and a visualforce page to insert the lead information.
This system doesn't work for the lead that fired the process builder, instead it works
if I insert an id of existing lead.
Which is the problem?
Apex class:
Thanks!!
I need to create a pdf (with the lead information) when a lead is created, this pdf is saved as document.
I wrote an apex class with an invocable method which fire in a process builder after
a lead creation, and a visualforce page to insert the lead information.
This system doesn't work for the lead that fired the process builder, instead it works
if I insert an id of existing lead.
Which is the problem?
Apex class:
public class PdfLead { @InvocableMethod(label='PDF' description='creo dei pdf') public static list<Document> pagePdf(){ Lead l = [select id, name from lead order by CreatedDate desc limit 1]; PageReference pdf = Page.PageOfLead; pdf.getParameters().put('id', l.Id); Blob body; try{ // returns the output of the page as a PDF body = pdf.getContent(); } catch (VisualforceException e) { body = Blob.valueOf('Some Text'); } List<Document> doc = new List<Document>(); Document d = new Document(); d.folderid='00lU00000018TxaIAE'; d.Name = l.Name; d.Body = body; d.ContentType = 'application/pdf'; d.Type = 'pdf'; doc.add(d); insert doc; return doc; } }Visualforce page:
<apex:page StandardController="Lead" renderAs="pdf"> <h2>Gentile {! Lead.Name }</h2> <br/> Ci risulta che lei lavora presso {!Lead.Company}<br/> <br/> Siamo riusciti a creare il file pdf con i suoi dati<br/> Grazie per aver richiesto informazioni per i nostri prodotti<br/> </apex:page>
Thanks!!
have you found the solution for this problem? Because I'm having the same issue..
I did have the same problm about only one field that i want to show in my pdf. so i tried to implement the trick but with no succes.
The solution that i found is to pass the field directly in my url and then use the code below in your visualforce :)