Please help me for fix my problem.

So.. i have vfp like this, enter image description here

This is my code for refresh the page. In controller i also clear and set to null for the variable.

<apex:page controller="ProcessPaymentController">
function confirmPreProcess()
      if(confirm('Are you sure to Pre Process this Payroll ?'))
          //document.getElementById("j_id0:j_id2:PreProcess:j_id3:j_id4:listPayrollName").value = "";
          //document.getElementById("j_id0:j_id2:PreProcess:j_id3:j_id8:listPackage").value = "";
            alert("Dont Execute");
    <apex:form >
        <apex:pageBlock title="Pre Process Payroll" id="PreProcess">

But, after i execute button process, the vfp return like this. enter image description here

As if the page was refreshed, but i think it doesn't. And I f I choose the Payroll name, and package Name again and execute. I will given error like this :

Insert failed. First exception on row 0 with id a0N4C0000006uDdUAI; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id] [![enter image description here][3]][3]

So, I need to manually refresh and execute again the process. Could you please help me? Thank u for your help.. :)

  • May I see your button code for Pre process, please? I mean the page one, e.g. <button id="pressBtn"> Press me!</button> – Lance Shi Nov 28 '16 at 4:36

I am not 100% sure because you haven't added your button code. But if your button code is something like this:

  <button id="pressBtn">

Then that is the reason you have having this issue. button has button and submit types and you need to specify it. Otherwise, different browser will treat it differently. In chrome, the default is submit. And if the button action is a submit, the page will not refresh its view state.

In order to resolve this, simply fix the button code as:

  <button id="pressBtn" type="button">


I tested with <apex:commandButton id="RunPreProcess" value="Pre Process" action="{!RunPreprocess}" />

Since apex:commandButton is actually a form submission, so it WILL NOT refresh the page reload the view state, which means the values will still be kept. So basically you can't redirect using oncomplete method. You need to redirect it using your commandButton method.

Something like below:

public pageReference RunPreprocess()
    pageReference pr = Page.firstTestPage;
    pr.setRedirect(true); //This line cannot be omitted
    return pr;

Although setRedirect is default to be true, the line pr.setRedirect(true) cannot be omitted if it is the same page.

Try the above code and it is working for me.

  • Hi Mr Shi, here my code for the button pre process : <apex:commandButton id="RunPreProcess" value="Pre Process" onclick="confirmPreProcess()" action="{!RunPreprocess}" /> the button call function RunPreprocess in ProcessPaymentController controller – Nicky Nov 28 '16 at 5:01
  • @Nicky I have updated my answer based on your comments – Lance Shi Nov 28 '16 at 5:20
  • Thank u Mr @Shi for help. I change my function from : public void RunPreprocess() { ...} to---> public pageReference RunPreprocess(){ PageReference vpr = new PageReference('/apex/Process_Payment'); vpr.setRedirect(true); return vpr;} – Nicky Nov 28 '16 at 8:00

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.