• David89
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
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:
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!!
 
If anybody delete my record from "Dipendenti__c" send notification to that mail.
In this code mail is not sending.
Please verify the code

trigger mailDelDip on Dipendente__c (before delete) {
    Messaging.reserveSingleEmailCapacity(trigger.size);
    List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
    for (Dipendente__c dip : Trigger.old){
    
    Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); 
    email.setToAddresses(new String[] {'montorselli.daniele@gmail.com'}); 
    email.setSubject('Automated email: dipendente eliminato');    
    email.setPlainTextBody('Attenzione è stato cancellato un dipendente');
    emails.add(email);         
        }
    Messaging.sendEmail(emails);
    for (Dipendente__c dip : Trigger.old){
        dip.addError('Unable to delete record!');
    }
    }
If anybody delete my record from "Dipendenti__c" send notification to that mail.
In this code mail is not sending.
Please verify the code

trigger mailDelDip on Dipendente__c (before delete) {
    Messaging.reserveSingleEmailCapacity(trigger.size);
    List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
    for (Dipendente__c dip : Trigger.old){
    
    Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); 
    email.setToAddresses(new String[] {'montorselli.daniele@gmail.com'}); 
    email.setSubject('Automated email: dipendente eliminato');    
    email.setPlainTextBody('Attenzione è stato cancellato un dipendente');
    emails.add(email);         
        }
    Messaging.sendEmail(emails);
    for (Dipendente__c dip : Trigger.old){
        dip.addError('Unable to delete record!');
    }
    }