I have a Visualforce page (Call VF1) which does some processing and updates a Custom object (Sales_Prints__c). After updating the sales_prints__c on VF1 I need to call another visualforce page (Call VF2) which pulls the values from sales_prints__c and creates a PDF (I’m using renderAs=“”pdf to achieve this). However when VF2 is trying to pull the values it is showing me the old values not the values which were updated by VF1. If I reload the VF2 page manually I can see the new values properly.

I’m stumped! Is this a SOQL cache issue?

Here’s what I tried doing:

  1. Adding a custom sleep function on VF2 just to cause a delay as I thought it was a timing issue at first. But this did not work.
  2. Adding FOR UPDATE on VF1, but this did not work either.

Can anyone help me with this?

  • are you using SOSL? i have seen this issue with SOSL but not SOQL. With SOSL it make sense as it need to update indexes which take few seconds. but SOQL should not give this kind of result. – AtulRajguru9 Feb 21 '20 at 4:28

Since v34.0, both getContent and getContentAsPDF are treated as callouts. This means that a separate transaction is spawned, and the original is placed on hold. This is problematic, because it also means that the previous transaction has not committed its changes to the database, so the page being called can't see those changes. This happens no matter how much of a delay you try to use or any locking statements. It simply won't work. What you need to do is to allow the current transaction to complete, then perform the PDF callout later. Using apex:actionFunction and oncomplete can be useful here:

<apex:actionFunction name="generatePDF" action="{!generatePDF}" reRender="form" />
<apex:commandButton value="Save" action="{!saveData}" oncomplete="generatePDF()" />

In pure Apex, you'd have to use a Batchable, Queueable, future, or Schedulable class, which means the PDF won't be available in the original context that called it. If you're just saving it somewhere, this might be acceptable, otherwise you'd need an additional call back to the server to get the results.

Finally, Blob.toPdf() could be used to convert HTML source to a PDF; you might just want to generate all the HTML "manually" and use this method to get the final output. A bit more annoying, probably, but can get the job done in a pinch.


You can check following things.

1) Run same SOQL and from console and see if its returning correct result
2) check to see of there is trigger which is revering your changes to record
3) are there any sort of integration those are reverting your changes

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.