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
Akshata ShahAkshata Shah 

Prevent Second click on custom buttom

Hello Friends,
I have custom button on custom object.
custom object calls VF page and controller.
How i can prevent second click on custom button using checkbox(true or false)
On second it should display error message like
"Cant click for second time".
Pleas help me!
Thank you
Akshata
ANUTEJANUTEJ (Salesforce Developers) 
Hi Akshata,

I found in the apex:commandButton tag developer documentation that there is something called as ondblclick this calls the function when the button is clicked twice, one possibility is to show an alert message when ondblclick fires.

>> the above is persent in the link- [ https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_commandButton.htm ]

I hope this as helpful in your implementation and in case if it helped can you please choose this as the best answer so that it can be used by others in the future.

Regards,
Anutej
Pawel BorysPawel Borys
Hi,
We are talking about a custom button which opens a Vf page and is placed on a custom object's layout, is that right? In that case I'm afraid you cannot add any logic to it. You will have to modify the VF page to check for the checkbox.
Pawel BorysPawel Borys
You can check the checkbox status in the apex controller and based on that either do whatever the page is supposed to do or just show a message about the button being already clicked.
You can use rerender to decide if and when the js script is supposed to run (Example (https://salesforce.stackexchange.com/questions/100157/call-javascript-function-from-apex-method))
Akshata ShahAkshata Shah
Hey Anutej
I have try this code
<apex:page standardController="CustomObject__c" extensions="MyController" action="{!MyControllerMethod}" >  
<apex:form >
        <apex:commandButton action="{!MyControllerMethod}" value="Download Salary Slip" rendered="{!IF(CustomObject__c.ButtonClick__c==true,false,true)}"/>
    </apex:form>
    <script>
    window.location.href="/{!CustomObject__c.ID}";
    </script>
</apex:page>

But still not working 
Please tell me where am wrong?
Reply me!

Regards,
Akshata