I have a visualforce page with the code below. I am calling a apex method on page load that gets the pages content to send in an email. The getContent function returns junk information if called this way. If I call the same method via a commandButton, getContent returns the correct html. Why is this? I can see in the debug log that there is a slight difference in the pageReference. The variable AJAXREQUEST is sent when called by the actionFunction.

actionFunction debug:


commandButton debug:


<apex:form id="form" >
    <apex:actionFunction action="{!PaymentPostProcessing}" name="loadDocuments" rerender="form" />
    <apex:commandButton action="{!PaymentPostProcessing}" value="Send my email"/>

<script type="text/javascript">

1 Answer 1


The difference is the rerender="form" attribute. If you add that to the apex:commandButton, you should see similar output. The fix is to remove this attribute if you want an apples-to-apples comparison. It's been a while since I've done this, but removing that attribute should result in your desired output.

  • You are right. If I add the "rerender" to the button I get junk data. If I remove it from the actionFunction the data is good but it continually refreshes the page. How can I prevent this?
    – Robinson
    Oct 20, 2022 at 21:24
  • @Robinson Personally, I'd consider separating out this logic into another page, then use apex:include to load the original page and get its content.
    – sfdcfox
    Oct 20, 2022 at 21:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .