2

I'm using actionFunction in a few Visualforce pages to call a custom save method. Although it works perfectly in regular Salesforce, it does nothing in the customer portal. If I instead call the method from a commandButton, it works OK. I already checked the debug logs, and with actionFunction, the method is not even reached.

Markup:

<apex:commandButton onmouseup="j$.Watermark.HideAll(); Save();" value="Save" />
<apex:actionFunction name="Save" action="{!saveRecord}"/>

In case you're wondering about the Watermark.HideAll(), I've already checked that it is not the problem. Removing it doesn't change anything, but calling the method directly from the commandButton works.

Any ideas why?

[Update]: Thanks to Steven's question, I tested it across browsers: it works in Chrome and doesn't work in Firefox and IE. Now, I'll strip the page of most other elements and test actionFunction with a simple form. I'll update soon.

[Update 2]: I answered my own question below with vital input from Mark Pond.

4
  • 1
    Is there any output in your browser console? Apr 24, 2013 at 13:29
  • Nothing. It is clean.
    – geeljire
    Apr 24, 2013 at 17:56
  • are you using IE and are you suppressing the standard SF UI in your VF page? Apr 25, 2013 at 4:31
  • No IE. Yes, standardStylesheets is set to "false", but it doesn't seem to be the culprit. Have you seen it affect actionFunction before?
    – geeljire
    Apr 25, 2013 at 11:44

4 Answers 4

2

Adding my earlier comment as an answer.

What is happening here is that the button click is calling the action function (which is a form post), which is immediately followed by the normal button click behavior which is also a form post.

Your button's JavaScript onmouseup needs to return false in order for the secondary form post to not occur.

Try this: <apex:commandButton onmouseup="j$.Watermark.HideAll(); Save(); return false;" value="Save" />

0
2

After much debugging, it appears that calling actionFunction from a commandButton or commandLink is problematic in Firefox and IE, but calling it from an anchor tag works fine.

The problems arise if actionFunction is the last or only function called from the commandButton/commandLink. However, if something else is called after the actionFunction, it appears to work fine.

Update: Mark's explanation below seems the most plausible, and it worked after I changed onmouseup to onclick:

<apex:commandButton onclick="j$.Watermark.HideAll(); Save(); return false;" value="Save" />

In conclusion, the problem was not related to actionFunction after all. Instead,it is related to the occurrence of multiple form posts connected to commandButton.

1
  • 3
    What is happening here is that the button click is calling the action function (form post), which is immediately followed by the normal button click behavior which is also a form post. Your button's javascript onmouseup needs to return false in order for the secondary form post to not occur. Try this: <apex:commandButton onmouseup="j$.Watermark.HideAll(); Save(); return false;" value="Save" />
    – Mark Pond
    Apr 25, 2013 at 17:35
0

a wildthought, but try changing name of actionFunction from Save to something different, I hope it does not get mixed up with standard Save methods of salesforce. I prefer using custom names of methods and variables so as to not to interfere with standard methods of salesforce codebase.

1
  • Nope, that's not it.
    – geeljire
    Apr 24, 2013 at 17:58
0

I've run into similar issues, although not specific to customer portal, where an action doesn't get called due to a pre-submit validation failure. You might try double checking you have an <apex:pageMessages/> tag on the page which will display the failure.

That said, the fact it works with a command button isn't a great sign ...

1
  • Good thought Ralph. I have that on the page already and it displays validation errors correctly.
    – geeljire
    Apr 25, 2013 at 12:34

You must log in to answer this question.

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