This post is regarding to avoid one small issue I have come across it.
Let say there is a visual force page where input fields and one button is present. When that button is clicked records are inserted in to the object. If button is clicked twice in same time(double click) then records(duplicate records ) are being created twice.
How will we avoid that?
How will restrict user to do double click on button?
Here I am sharing some snippet of code.Hope It will help you.
<apex:form >
<apex:pageMessages id="messages"></apex:pageMessages>
<apex:pageBlock title="Avoid Doublle Click" >
<apex:pageBlockButtons location="both">
<apex:actionStatus id="saveStatus">
<apex:facet name="stop">
<apex:outputPanel >
<apex:commandButton action="{!save}" value="save" reRender="messages" status="saveStatus"/>
<apex:commandButton action="{!Cancel}" value="Cancel" immediate="true" />
</apex:outputPanel>
</apex:facet>
<apex:facet name="start">
<apex:outputPanel >
<apex:commandButton value="Saving..." disabled="true" />
<apex:commandButton value="Saving..." disabled="true" />
</apex:outputPanel>
</apex:facet>
</apex:actionStatus>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Account Creating">
<apex:inputField value="{!Account.Name}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Let say there is a visual force page where input fields and one button is present. When that button is clicked records are inserted in to the object. If button is clicked twice in same time(double click) then records(duplicate records ) are being created twice.
How will we avoid that?
How will restrict user to do double click on button?
Here I am sharing some snippet of code.Hope It will help you.
Page:
<apex:page standardController="Account"><apex:form >
<apex:pageMessages id="messages"></apex:pageMessages>
<apex:pageBlock title="Avoid Doublle Click" >
<apex:pageBlockButtons location="both">
<apex:actionStatus id="saveStatus">
<apex:facet name="stop">
<apex:outputPanel >
<apex:commandButton action="{!save}" value="save" reRender="messages" status="saveStatus"/>
<apex:commandButton action="{!Cancel}" value="Cancel" immediate="true" />
</apex:outputPanel>
</apex:facet>
<apex:facet name="start">
<apex:outputPanel >
<apex:commandButton value="Saving..." disabled="true" />
<apex:commandButton value="Saving..." disabled="true" />
</apex:outputPanel>
</apex:facet>
</apex:actionStatus>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Account Creating">
<apex:inputField value="{!Account.Name}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>