+ Start a Discussion
liron169liron169 

Strange behaviour with attachment as PDF

Hi,
I have page generate as PDF with huge amount of data. Due to the amount of data it sometimes fail (seems like timeout when loading the page, no excpetion on SF limitations).

I tried as solution to generate the page in memory and add as PDF attachment. Wrote small class (below) for testing and run it from the developer console.
When I run it for small data all is fine and its working.
But if I try it with huge data then, for some wired reason, I see that the page being generated over and over every minute (I see every minute call in the developer console), and add attachment per each run.

If I try it with very huge amount of the data, then also the page being generated every minute, but no pdf attachment is created (also can see internal error exception but without other information).

At first, I thought it's something in the code, but as it is working fine for small set of data, I'm thinking it's something internal for SF? Maybe someone have idea for this behavior?
+ Any other suggestions to enhance this process- to support huge data - will be welcome (I don't think it's related to crappy or un standard code, it's simply too much data, so I'm looking for general approach for this)

Thanks.

global class AddPdfToRecord{
   
    webservice static void addPDF(){
      
       pageReference pdf = Page.RepTestLiron;
      
      
       pdf.getParameters().put('cfr','test');
       pdf.getParameters().put('cto','');
       pdf.getParameters().put('del','');
       pdf.getParameters().put('efcont','A');;
       pdf.getParameters().put('hv','A');
       pdf.getParameters().put('repid','a1zD0000000L6WmIAK');
      
       system.debug('URL: ' + pdf.getURL());

       Attachment attach = new Attachment();
       Blob body;
       try
       {
           body = pdf.getContentasPDF();
       }
       catch(Exception e)
       {system.debug('EEEEEEEEEEEEEEEE'  + e) ;}
       attach.Body = body;
       attach.Name = 'FMR_TEST.pdf';
       attach.IsPrivate = false;
       attach.ParentId = '001D000000wqkSY';
           
        
        
       insert attach ;
    }
}
Satyendra RawatSatyendra Rawat
Hi Liron,
I have added one line pdf.setRedirect(true);

global class AddPdfToRecord{
  
    webservice static void addPDF(){
     
       pageReference pdf = Page.RepTestLiron;
     
     
       pdf.getParameters().put('cfr','test');
       pdf.getParameters().put('cto','');
       pdf.getParameters().put('del','');
       pdf.getParameters().put('efcont','A');;
       pdf.getParameters().put('hv','A');
       pdf.getParameters().put('repid','a1zD0000000L6WmIAK');
     
       pdf.setRedirect(true);


       system.debug('URL: ' + pdf.getURL());

       Attachment attach = new Attachment();
       Blob body;
       try
       {
           body = pdf.getContentasPDF();
       }
       catch(Exception e)
       {system.debug('EEEEEEEEEEEEEEEE'  + e) ;}
       attach.Body = body;
       attach.Name = 'FMR_TEST.pdf';
       attach.IsPrivate = false;
       attach.ParentId = '001D000000wqkSY';
          
       
       
       insert attach ;
    }
}
liron169liron169
Thanks,
But I added this line, and it doesn't help.

And again, it's happen only for huge amount data, with several records I don't see this problem.
liron169liron169
Just update.
I notice that this issue happen only while the developer console remain open.
When I close it, it's stopp to re-run the page, and create additional attachments.

Still no idea why it's happen.