I have run into an issue with an apex:command button, where the oncomplete part of the process is not being called, and prevents the button from completing its action.

The VF page is a component on a record page, so the refresh is JS to reload the page (not just the component vf page).

The pages class supplies the return URL ({!redirectUrl})

The VF Button

value="Reject (Entry Criteria)" 
onclick="return confirm('Are you sure?');" 

The JS

function refreshPage(){window.top.location.href = '{!redirectUrl}';}

If I use the above setup, the Confirm dialog appears, the action does not fire and the page is not refreshed

If i remove onComplete, the Confirm dialog appears, the action fires successfully, and the page is not refreshed.

If i remove onClick, the Confirm dialog does not appear, the action fires successfully, and the page is refreshed.

So it seems you cant have onClick and onComplete in the same button??

Any thoughts?



1 Answer 1


The following works in my testing:

<apex:commandButton value="Reject (Entry Criteria)" onclick="if(!confirm('Are you sure?')){return false};" 
action="{!debugSomething}" oncomplete="refreshPage();" />

From the linked duplicate:

onclick="return confirm('Are you sure?');" is always returning before calling the code to the controller method. What I have done is to wrap the return in an if statement and call it only if the condition is correct. The code below will call return if the confirmation is false

I did not know this until I did some testing for your question. Learn something new every day

  • Thanks Eric, I did try something similar to this, but was unsuccessful. Works as intended! Commented Aug 23, 2017 at 2:40

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