I have one page that modifies a record but before the code finishes, it calls another page. The second page queries the values in the record but I'm assuming that my transaction from the update hasn't completed because the code hasn't finished. I am getting the content of the second page to add as an attachment. The problem is that I set a value on the record before generating the second page in memory. I'm then guessing that the transaction from the update hasn't completed then I build the second page in memory and it queries the field that I changed but gets the previous value because the transaction hadn't been fully committed.

Is there a way to force the commit before my code block exists so that the second page gets the correct value?


No, you can't force a commit. The specific reason why is because commits occur at the end of the entire transaction. The data is committed after the DML, but isolated from the rest of the database until after the page finishes (so it can roll back in the event of an exception).

Shared View State

If the page shares the same controller and extensions as the current page, the view state should be transparently passed to the page you're calling getContent() on. This said, you don't need to query anything, because the data will already be present in the controller.

Multiple Calls

You can use an actionFunction to chain together multiple calls. You necessarily need to use a reRender attribute for this to work.

    <!-- other intervening stuff here -->
    <apex:actionFunction action="{!sendEmail}" reRender="" name="sendEmail"/>
    <apex:commandButton action="{!updateRecord}" reRender="" value="Save & Send" oncomplete="sendEmail()"/> <!-- the last sendEmail is JavaScript! -->
|improve this answer|||||
  • Tried the static variable. It isn't working but it may be to complexity of the second page. There are multiple controllers for multiple sections. A Java programmer wrote them and abstracted the crap out of things so the page has more layers than an onion. – Robert Harper Dec 26 '13 at 21:15
  • @RobertHarper I've had to do that myself, in which case it can definitely become painful. I am pretty sure the static method should work; I'll see if I can't draft up a working demonstration for you shortly. – sfdcfox Dec 26 '13 at 21:43
  • I tried the static method but because of the way the second page is created, it gets a separate context and the static value returned null in the second page. – Robert Harper Dec 26 '13 at 22:19
  • @RobertHarper It appears you're correct on that front. I could have sworn I had previously made something work that way, but no such luck here. I'll amend my answer. – sfdcfox Dec 26 '13 at 22:21
  • actionFunction not working. Because I have also inputfield field, I cannot use actionFunction directly, so I surround it with actionRegion but it still not working <apex:actionRegion> <apex:commandLink action="{!updateData}" oncomplete="sendEmail()" >Send Email</apex:commandLink> </apex:actionRegion> – unidha Mar 31 '15 at 1:35

The way we fixed this was to add the page controller that held the state to the other pages so that the state could be persistent across the pages.

|improve this answer|||||

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.