You need to sign in to do that
Don't have an account?

How to disable the save button before clicking second time.
There is a visualforce page with extension controller class.If we click the save button twice , 2 records are creating at a time.
can we disable the button once the button is clicked just like standard functionality. I tried with different ways , can able to disable the button but could not able to prevent the double click .
Hi,
Try the below code snippet as reference:
<script>
function hidefield()
{
document.getElementById("fieldIDtobehide").style.dispaly = "none";
return false;
}
</script>
<apex:commandbutton onclick="return hidefield();"/>
<input type="text" id ="fieldIDtobehide" />
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Hi
This is one way you can avoid multiple records creation:
* You can use DML operation "UPSERT" when your button is clicked.
So in case user clicks multiple time only records will get updated
This script not working . when we are creating a record related to standard object and once after req fields are filled and click save , all the buttons gets disabled( so no chance of clicking it for the second time) . Here in this customized app it is not getting disabled(blur) , so if i click it twice 2 records are created with same name.
when you save a record are you not moving to the detail page of the record. or your page is not getting refresh for the first click and not loosing values from the fields.Jst check out when a record is saved why you are again with in the same page to have chance to click second time the same save button .
If you had to stay in the same page even after the save button pressed you can make disable by setting a flag
for example
boolean flag= true;
before clicking the button rendered="{!flag}" onclick="{! ! flag}"
If this answers your question make this as solution.
Yeah you can do that but instead of using rendered use disabled like below
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandbutton action="{!disableButton}" value="Save" disabled="{!flag}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection >
Controller code
public Boolean flag { get ; set; }
public PageReference disableButton()
{
flag = true;
return null;
}
In constructor make that flag as true so that it won't be disabled for the first time
can able to create the record , once you click the save button it takes like 1-2 sec(approx) time to save the record , with in that time if we click button the next time one more record is created with same name . Here once after clicking save button , it should disable and record has to be saved.
ok then after first click hide the save button as i said using rerenderd
for that what you have to do is
<apex:PageblockButtons id="xyz">
<apex:command button action="{!save} rendered="{!flag}" rerendered="xyz"/>
</apex:pageblockButtons>
set the flag= true in ur constructor and flag =false when your are going out of save method.
Ihope this will solve your problem.
Feel free to post if any doubts on this.
not working ,here we should not even go to the controller, everything should be done in client side
<apex:pageBlockButtons >
<apex:actionStatus id="go">
<apex:facet name="stop">
<apex:commandButton value="Save" action="{!Save}" status="go" disabled="false"/>
</apex:facet>
<apex:facet name="start">
<apex:commandButton status="go" value="Saving..." disabled="true" />
</apex:facet>
</apex:actionStatus>
I tried this way not working either
did you use the javascript method as one of the member said when you cant rely on controller , you do the things using javascript try it.
all d best.
<apex:pageBlockButtons >
<apex:actionStatus id="go">
<apex:facet name="stop">
<apex:commandButton value="Save" action="{!Save}" status="go" disabled="false" rerender = "go"/>
</apex:facet>
<apex:facet name="start">
<apex:commandButton status="go" value="Saving..." disabled="true" />
</apex:facet>
</apex:actionStatus>
Finally this works
Thanks All
In your custom controller extension, at the end of your save method you can use the pagereference class, such as,
There are more ways to use this class deatiled in the api docs here,
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_system_pagereference.htm
The very last code exmaple on that page has what you are looking for, "When a user clicks Save, he or she is redirected to the detail page for the account just created:"