2

I have used actionfunction to redirect visualforce page to another page but the page is not redirecting into another.

VF Page:

<apex:commandButton value="Create" onclick="createfunction()" />
<script>
   function createfunction(){
        <!-- some operations -->
        create(param1,param2); 
   }
</script>
<apex:actionFunction name="create" action="{!create}" reRender="">
     <apex:param name="one" value="" assignTo="{!value1}" />
     <apex:param name="two" value="" assignTo="{!value2}" />
</apex:actionFunction>

Apex Controller:

Public PageReference create(){
     PageReference oppPage = new PageReference('/'+oppId);
     oppPage.setRedirect(true);
     return oppPage;   
}

Can any one help me how can i resolve this issue.

  • Any errors in your browser's console? Also, have you tried changing the commandButton to plain HTML input? – Boris Bachovski Apr 11 '16 at 6:34
  • I didn't get any console errors. I tried by replacing command button with html input button, but still same problem am facing. – Murali Mohan M Apr 11 '16 at 6:50
  • Is the apex method getting called at all? Chuck a system.debug there and double check. And try move the action function above your script – Boris Bachovski Apr 11 '16 at 6:52
2

try

<apex:commandButton value="Create" onclick="createfunction(); return false;" />
  • Can you add some explanation to your post? – Adrian Larson Jul 21 '16 at 13:30
0

Just use input button instead of command button and you need to use two action functions one for calling controller method and the other one for redirecting to another page after the first action function has been completed:

<apex:form id="form">
   <apex:actionFunction name="doSmthng" action="{!doSomething}" reRender="optpnl" oncomplete="gotopg();">
      <apex:param name="paramName" value="" />
  </apex:actionFunction>

  <apex:actionFunction name="gotopg" action="{!gotoMyPage}"/>

<apex:outputPanel id="optpnl">
   <input type="button" value="Do Something" onclick="doSmthng();"/>

inside the controller:

public void doSomething(){
  String prm = ApexPages.currentPage().getParameters().get('paramName');
}

public PageReference gotoMyPage(){
   return Page.myPage;
}

....
0

Is there any specific reason of using actionFucntion? Why not direct commandButton with params?

<apex:commandButton value="Create" action="{!classActionMehthod}" reRender="panelId">
<apex:param name="anyName" value="anyValueOrBlank" assignTo={!classVariable}"/>
</apex:commandButton>
  • You have to keep "reRender" in the button syntax to keep param working.
  • Keep it blank or surround your page code in and give panel id.

Hope this works.

  • OP's question references a create action and your answer uses 'delete'. Answer is a bit confusing. If you mean to show a generic commandbutton, perhaps changing to <apex:commandButton value="Foo" action="{!someAction}" reRender="someID"> – cropredy Jun 17 '16 at 21:37

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.