I have a custom button which generates and sends an invoice pdf. Just before to generate the pdf, if the issue date of the invoice is null, I set the date to today, then I generate the PDF. The code looks something like :
Invoice_Header__c inv = [select id, Issue_Date__c from Invoice_Header__c where Id = 'a0TN0000000kurH'];
System.debug('$1-- Issue Date = '+inv.Issue_Date__c); // my issue date = null here
if (inv.Issue_Date__c == null)
{
inv.Issue_Date__c = System.today();
update inv;
}
//reload the invoice just in case I would have something weird in trigger/workflow
inv = [select id, Issue_Date__c from Invoice_Header__c where Id = 'a0TN0000000kurH'];
QUtils.debug('$2-- Issue Date = '+inv.Issue_Date__c); //it displays the right date here ==> today
//then I call my pdf
PageReference pdf = new Pagereference('/apex/MyInvoicePDF?id='+inv.Id);
Blob b = pdf.getContent();
.....
My 'MyInvoicePDF' page is linked to a standard + custom controller
<apex:page standardcontroller="Invoice_Header__c" extensions="MyInvoicePDFCtrl" renderAs="pdf" sidebar="false" showHeader="false" applyHtmlTag="false">
In my custom controller, I display the Issue Date of my invoice, however the issue date is still null :
public MyInvoicePDFCtrl(Apexpages.StandardController controller)
{
...
Invoice_Header__c invoice = [select id, Issue_Date__c from Invoice_Header__c where Id = 'a0TN0000000kurH'];
System.debug('$3-- Issue Date = '+invoice.Issue_Date__c); //my Issue Date is still null here
...
}
Is there anyone who got the same problem before ? Is it a timing/cache issue ?
Cheers
David