Using a simple action function and param to pass a value to a controller, but receiving the following in the browser.

Uncaught SyntaxError: Unexpected token ':'

Exception caught on ':' in doAThing=function(j_id0:

When I remove the param, I do not run into the exception.

VFP Code:

    <apex:actionFunction name="doAThing" reRender="refreshPanel"
                         onComplete="doThisOnComplete()" action="{!doAThing}">
    <apex:param value="" assignTo="{!variableFromVfp}"></apex:param>    

Rendered in the browser as:

<script id="j_id0:j_id1:j_id7" type="text/javascript">
doAThing=function(j_id0:j_id1:j_id8){A4J.AJAX.Submit('j_id0:j_id1',null,{'similarityGroupingId':'j_id0:j_id1:j_id7','oncomplete':function(request,event,data){proceed()},'parameters':{'j_id0:j_id1:j_id7':'j_id0:j_id1:j_id7','j_id0:j_id1:j_id8':(typeof j_id0:j_id1:j_id8!='undefined'&&j_id0:j_id1:j_id8!=null)?j_id0:j_id1:j_id8:''} } )};

You need to specify a name attribute, or you would get unexpected behavior.

<apex:param name="aValue" value="" assignTo="{!variableFromVfp}"></apex:param>
  • Thanks, but whats the cause for the unexpected behavior? Name attribute is not a required field according to the docs: developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/… When this converts to a JS function on the page, why does it need a name?
    – S.B.
    Jan 19 '20 at 7:53
  • 1
    @S.B. Thanks for reminding me, it's been a while. Actually, name isn't needed if you do not use reRender on the parent element, everything just works. However, because of how VF generates names, the AJAX framework used for reRender, and the rules of JavaScript, not providing a name causes this behavior. I'm going to bring this up with the doc team (for the second time, if I recall), because the docs are misleading and/or the platform is not working as documented. For now, just pretend name is actually documented as being required.
    – sfdcfox
    Jan 19 '20 at 15:02

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.