function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
newbie2010newbie2010 

Multiple clicks to Submit button causing multiple identical records

I have created a custom web form to enter information into a custom object. Everything works great except for the submit button. We recently had someone enter two identical records almost immediately so I went into our sandbox to test my theory and, unfortunately, I was correct...if you click the submit button multiple times before the page processes and redirects to the thank you page it will generate multiple identical records based on the number of times the button was clicked. Is there anything that can be done to ignore the multiple clicks and process only one record instead of duplicating it?

 

 

Thanks!!

sjain1.2523113033806995E12sjain1.2523113033806995E12

Hi,

      One thing you can do this functionality after click on submit button you can disable the button so that you can avoid duplicate records.

newbie2010newbie2010

I have researched that and lack of experience/time can't determine best method of coding.  it won't let me code in controller extension (unless coding it incorrectly).  Tried in the page, within the form, and every time I click anywhere on the page (to enter data) it tries to submit the page, but obviously gives me a bunch of errors since I haven't entered any data.  Tried putting code outside of form and that did nothing.

 

Any help in proper implementation would be greatly appreciated, an example possibly...

sjain1.2523113033806995E12sjain1.2523113033806995E12

<apex:commandbutton onclick="Disablebutton()" action="{!dummy}"/>

<script>

function Disablebutton()

{

  document.GetElementById(pageid:formid:componentId).disabled = true;

}

</script>

 

 

newbie2010newbie2010

Will that interfere with submitting the form and redirecting the page to a thank you page?

sjain1.2523113033806995E12sjain1.2523113033806995E12

Tryout with the above sample code and let me know if there is any conflict ....

newbie2010newbie2010

You will have to excuse my lack of experience...I tried incorporating that into my page, but it didn't like that at all.  I will try other avenues of getting the code you suggested into my page and will let you know.

 

Thanks!

jcressardjcressard

I have the same problem, and the JS code doesn't work... =(

jcressardjcressard

The JS Code works, my bad ! Thanks :)

newbie2010newbie2010

How did you implement the code to get it to work?

jcressardjcressard

Exactly like sjain1.2523113033806995E12 said, i added onclick="Disablebutton()" on my apex:commandButton, and i copied the script 

 

function Disablebutton()

{

  document.GetElementById(pageid:formid:componentId).disabled = true;

}

</script>

 

just below my commandButton, and it works :)

newbie2010newbie2010

Ok, it's not working so I am including the code below to see if I can get any suggestions.  This is the code in the page itself...

 

   <apex:commandButton value="Submit" onclick="Disablebutton()" action="{!saveTransmittal_WebForm}"/>
   <script>
   function Disablebutton()
   {
   document.GetElementById(pageid:formid:componentId).disabled=true;
   }
   </script>

 

This is the code in the class extension...

 

public class myWeb2TransExtension {
       private final Transmittal_WebForm__c webtrans;
       public myWeb2TransExtension(ApexPages.StandardController stdController) {
          webtrans = (Transmittal_WebForm__c)stdController.getRecord();
       }
        public PageReference saveTransmittal_WebForm() {
          try {
            insert(webtrans);
              }
          catch(System.DMLException e) {
              ApexPages.addMessages(e);
              return null;
          }
          PageReference p = Page.TransmittalThankYou;
          p.setRedirect(true);
          return p;
        }
    }

 

Christopher PaineChristopher Paine
@sjain1.2523113033806995E12 that JS Vworks very well to solve this problem. Many Thanks!