Its not populating the correct Record of Product of Interest on VF page . I am calling it from screen flow in which i am updating the field of product of Interest record and after that i want to show that as a pdf on lead ,the problem is its showing on the flow that its getting the right record Id but when we open the document its not the correct record its randomly picking up the record i guess , and also here recordId = ApexPages.currentPage().getParameters().get('id'); System.debug('recordId >> '+recordId); I am not getting the Id but if i dubug the URL in that i am getting Lead Id

 global class pdfGeneratorForLead {
      global Id recordId {get;set;}
    global Product_of_Interest__c prodCon{get;set;}

   private ApexPages.StandardController stdController;
    global pdfGeneratorForLead(ApexPages.StandardController stdController){
        this.stdController = stdController;
        recordId = ApexPages.currentPage().getParameters().get('id');
        System.debug('recordId >> '+recordId);
        /*----- SELECT POI FROM THE LEAD --------------- */
       List<Product_of_Interest__c> poi = new List<Product_of_Interest__c>();
        Set<Id> CleanCheck = new Set<Id>();
        Set<Id> RustPreventive = new Set<Id>();
        poi = [SELECT ID, Product_Category__c FROM Product_of_Interest__c WHERE Lead__c =: recordId];
        System.debug('poi >> '+poi);
        for(Product_of_Interest__c P : poi){
            if(P.Product_Category__c == 'CleanCheck'){
                System.debug('CleanCheck >> '+CleanCheck);
            else if(P.Product_Category__c == 'RUST PREVENTIVE'){
                System.debug('RustPreventive >> '+RustPreventive);
        //----- SELECT POI FROM THE LEAD --------------- 
        prodCon = [SELECT Account__c,Achieved_Millipore_Value_Solids_in_mg__c,Washing_time_in_Minutes_Seconds__c,Weight_of_Job_in_Kg__c FROM Product_of_Interest__c WHERE Id =: CleanCheckLIMIT 1];
        System.debug('ProdCon >>>>> '+ prodCon);
    /*public static List<Account> pdfGeneratorForLead3() {
        List<Account> ch = [SELECT id FROM Account LIMIT 2];
        return ch;
    Global static void pdfGeneratorForLead2(List<Id> prodId) {
       // List<Product_of_Interest__c> prod = new List<Product_of_Interest__c>();
        System.debug('prodId >>>>>>>>> '+prodId);
     Product_of_Interest__c prod = [SELECT Account__c,Achieved_Millipore_Value_Solids_in_mg__c,Achieved_Millipore_Value_Soluble_in_mg__c,
                                   Job_washed_per_day_in_Nos__c,Washing_time_in_Minutes_Seconds__c,Weight_of_Job_in_Kg__c FROM Product_of_Interest__c WHERE Id = :prodId];
        System.debug('prod >>>>>>>>> '+prod);
        Id leadId = [SELECT ID FROM LEAD WHERE ID =: prod.Lead__c].Id;
        // Create a new PDF document
        PageReference pdf = Page.pdfCreator;
        pdf.getParameters().put('leadId', leadId);
        Blob pdfBlob = pdf.getContentAsPDF();
        // Create a new Attachment record and attach the PDF to the Opportunity
        Attachment attachment = new Attachment();
        attachment.Name = 'Recommendation form.pdf';
        attachment.ParentId = leadId;
        attachment.Body = pdfBlob;
        insert attachment;
        //call a future
      //  return prod;

This Is the controller

and this is the vf page

<apex:page standardController="Lead" extensions="pdfGeneratorForLead">

    <apex:pageBlock >
        <apex:pageBlockTable value="{!prodCon}" var="a"> 
            <apex:column value="{!a.Customer_Name__c}"/>
   <b>Quote Type :</b> {!prodCon.Customer_Name__c}<br/>
    <apex:outputText value="{!prodCon}"></apex:outputText>
  • Welcome to SFSE - can you edit your question so that it is clear what you asking?
    – Girbot
    Commented Mar 15, 2023 at 7:38
  • Updated @Girbot
    – user130294
    Commented Mar 15, 2023 at 7:45

1 Answer 1


I think your issue could be here:

Invocable method:

PageReference pdf = Page.pdfCreator;
pdf.getParameters().put('leadId', leadId);  // <== leadId

VF Controller

recordId = ApexPages.currentPage().getParameters().get('id'); // <== 'id'

Hence - mismatch

I'd have the invocable set pageParameter id and change the controller to use

recordId = stdController.getId();


instead of

recordId = ApexPages.currentPage().getParameters().get('id');

Standard Controllers always have access to the recordId because by definition, they operate on a record instance.

You must log in to answer this question.

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