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
arunadeveloperarunadeveloper 

How to disable a custom button on standard page layout

Hi There,

 

having custom button , when I click that button if one of my field on that object is ":Success" then diable a button. otherwise don't diable it.

 

I am having below code on my custom button , it is disabling button , but when i refersh the page again it is enabling back.

 

but I want to disable that button if the field is "success",  enable that button back if user changes any field or if they change form "success" some thing else not when they refersh the page.

 

 

var testSuccess='{!somename__c}';


alert("testsuccess="+testSuccess);


if(testSuccess=='Success'){


       this.disabled = true;
      this.className = 'btnDisabled'

 

}

 

 is that possible using custom button ? if it please let me know how to do that.

 

Best Answer chosen by Admin (Salesforce Developers) 
Bhawani SharmaBhawani Sharma
No, this is not possible to disable to button at the time of page load because javascript only executes when you clcik on button.

That's why, initial suggestion was to put an alert message instead on disabling the button.
if(testSuccess=='Success'){

alert('This record has already been processed');

} else {
// write your logic to process the record
}

All Answers

Venkat PolisettiVenkat Polisetti

You cannot manipulate Custom Buttons on a Standard page.

 

However, if you want to go the extra trouble and implement jquery and all that (it is quite a bit of work) on the home page layout, see the blog post by tehnrd (Jason) and that is what you need to do. He explained it well.

 

http://www.tehnrd.com/show-and-hide-buttons-on-page-layouts/

 

Thanks,

Bhawani SharmaBhawani Sharma
I would say, as this is a custom button, you can write some javascript code in your custom button and give a message to user under specific conditions that button is disabled
arunadeveloperarunadeveloper

Can you please give me an idea how to do that, or if you have sample code that will be great help.

 

Kiran  KurellaKiran Kurella

It looks like you already have the code:

 

var testSuccess='{!somename__c}';


alert("testsuccess="+testSuccess);


if(testSuccess=='Success'){

 

     alert('This record has already been processed');
 

} else {

    // write your logic to process the record

}

 

p.s. Please leave your feedback (Kudos), if the suggested solution is working.

arunadeveloperarunadeveloper

Thank you for ypur  replay, But If refersh the page again it is enabling back even if somename__c='Success'.

 

I want If the somename__c='Success' if i refersh the it should not enable , it should be enbled if i change the text from "Success" to something else.

 

Is it possible ?

Bhawani SharmaBhawani Sharma
No, this is not possible to disable to button at the time of page load because javascript only executes when you clcik on button.

That's why, initial suggestion was to put an alert message instead on disabling the button.
if(testSuccess=='Success'){

alert('This record has already been processed');

} else {
// write your logic to process the record
}
This was selected as the best answer