0

Not sure is the title is correct or not but this is my scenario.I have one controller to send email with pdf attachment to the user.Before it render the pdf file, it will update the user input first.

1) Class to send email

system.debug('@ Input ='+myObject1.input__c);
 if(myObject1.input__c!=null){
      update myObject1;
 }
system.debug('@ Input ='+myObject1.input__c);

PageReference pdfPlan=Page.GeneratePDF;
pdfPlan.getParameters().put('pdfId',myObject1.Id);

//code that attach pdf to the email and send the email

2)Class to get render the pdf using parameter from class (1)

public GeneratePDF(ApexPages.StandardController stdController) {
    if (system.currentPageReference().getParameters().get('pdfId') != '') {
     pdfId= system.currentPageReference().getParameters().get('pdfId');
   }

MyObject= [SELECT input__c, Id FROM object1__c WHERE Id =: pdfId LIMIT 1];

The issue is , the pdf render always get the old data.Not the latest data that updated in Class(1).I know the easy way is just to send the Input__c as parameter but how about if I have many fields to update.The object successfully update in Class(1) but it still getting the old data in PDF generation class.

It seem like the sequence is: it render pdf file first(query old data) then it update the data(update the latest value).But in my code I already put update before rendering PDF.

Any idea why this is happening?

1

The issue is related with PDF rendering (creating) that is executed in another parallel transaction, which doesn't wait for the first transaction to commit DB.

Your solution is to wait for first transaction to complete and then:

  • open blank VF page with action attribute present to immediately fire render method
  • using oncomplete attribute on commandButton (or whatever you are using: actionfunction, remote action, etc...) and fire controller method
  • in general: make sure that update is commited to DB and then render PDF.

Check out a similar theme.

| improve this answer | |
  • i m using actionFunction in oncomplete but still it is not working.My objective is to render pdf and attach it in the email.so my method contain pdf rendering and email attachment. – unidha Mar 31 '15 at 0:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.