1

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:

USER_DEBUG|[99]|DEBUG|System.PageReference[/apex/PaymentCancel?AJAXREQUEST=_viewRoot&com.salesforce.visualforce.ViewStateVersion=202210181905000187&j_id0%3Aform=j_id0%3Aform&j_id0%3Aform%3Aj_id38=j_id0%3Aform%3Aj_id38&prSetting=Payment_Request&req=61QK2IQW&result=cancel]

commandButton debug:

USER_DEBUG|[99]|DEBUG|System.PageReference[/apex/PaymentCancel?com.salesforce.visualforce.ViewStateVersion=202210181905000187&j_id0%3Aform=j_id0%3Aform&j_id0%3Aform%3AtheButton=Send+my+email&prSetting=Payment_Request&req=61QK2IQW&result=cancel]

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

<script type="text/javascript">
 window.onload=function()       
    {        
         loadDocuments();
    };
</script>

1 Answer 1

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.

2
  • 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 .