2

I have two function which needs to be called from one button. Currently I am doing this by creating two button one "Confirm" and another "Save". but I don't want two button I want only one button "Save", on click of Save first the method called by "Confirm" button should be called and then the method called by "Save" button.

Below is my code:

<apex:commandButton value="Confirm" action="{!save}"/>   
<apex:commandButton value="Save" action="javascript:top.window.opener.closeFunction()" ></apex:commandbutton> 
1
<apex:commandButton value="Save" action= "{!save}"
  Oncomplete="javascript:top.window.opener.closeFunction()" />

Instead of onclick try - oncomplete event.

0
0

You can bind the javascript call to onclick and then the apex call using action on the same button..

something like

<apex:commandButton value="Save" action= "{!save}"
  onclick="javascript:top.window.opener.closeFunction()" />
2
  • I tried this one but it's not working – salesforce Developer Jul 12 '15 at 18:23
  • u can different options.. try using oncomplete event if required.. or try moving the javascript code into a separate function.. – Vamsi Krishna Gosu Jul 12 '15 at 23:30
0

Another option: you can use javascript Remoting. First, you call the save action with javascript remoting. Then, in the callback, you call your second javascript method. This way, you are ceratin that the second function (the javascript function) fires after your apex function.

Here is an example of Javascript remoting: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_js_remoting_example.htm

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.