Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have custom button on standard detail page...I want to disable that button/gray out if my status picklist value is "Approved". Java script on button click

var newRecords = []; 
 var o = new sforce.SObject("Opportunity"); ="{!Opportunity.Id}"; 
   if ( o.Sub_Stage__c == 'Approved')
     // disbale button

Can some tell me how to do this..

share|improve this question
possible duplicate of Need some help with a custom button or button override – eyescream Jan 23 '13 at 5:45
You could try this.disabled = true but it would only disable on click. Alternatively JavaScript in sidebar or change RecordType via workflow, which changes page layout to one without the button. – techtrekker Jan 23 '13 at 7:15
@eyescream I don't think it's duplicate - That is about customizing a managed custom button, this is about conditionally displaying it. – Benj Jan 23 '13 at 16:15
@Benj still - trick described by Dr. Coleman could work. Or a sidebar JS injection since I've read in Spring '13 rel. notes they're going to kill the trick with JS injected into section headers... – eyescream Jan 23 '13 at 16:31
Same trick could work, but the questions are different. Even if the same answer applies, I wouldn't expect most users to be able to find the information since it's a different use-case. Not such a big deal, though, either way. – Benj Jan 23 '13 at 17:52
up vote 2 down vote accepted

Being able to show/hide buttons on a page layout in response to the record field values was the subject of a cloudspokes challenge.

Here's a link to a solution (not mine!) that utilises the Salesforce sidebar to host the javascript that manipulates the button. Note that this won't work for Service Cloud Console as the sidebar doesn't get displayed:

share|improve this answer
Thanks..great Solution...!!! – miku Jan 23 '13 at 9:35

I dont think it is possible to do so.

However, what you could possibly do is that, if you are using record types, add one more record type as "Approved". As the o.Sub_Stage__c field changes to Approved, change the record type to "Approved" (may need to write a trigger/workflow field update for this) and assign the page layout for this record type with the button hidden on this page layout.

May not be a straightforward solution but i hope this helps.

Here's an IDEA similar to your requirement:

share|improve this answer

You can call a javascript function on status picklist's onChange event and in that function you can check wheter status value is 'Approved' and based on that you can disable that button/gray out that through CSS.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.