Is there a way of changing a custom button color? Not a button on the visualforce page but rather the ones created under custom and links on an object.

Thanks. -K

up vote 61 down vote accepted

[comic but unsupported - don't do this]

This can be pulled off, but you need to get crafty :-) here's one I prepared with pink candy polka dots:

pink candy polka dots

  1. go to Setup > Create > Objects > [Your Object] > Custom Buttons and Links, and hit New,

  2. create a Detail Page Button whose behaviour is to Execute JavaScript,

  3. modify the following JavaScript, using your lowercased button name in lieu of your_button:

    (function() {
      var button = document.getElementsByName('your_button')[0];
      button.style.background = 'url("https://addons.mozilla.org/_files/311357/preview_small.jpg")';
    }());
    
  4. use a base64 encoder to format your JavaScript, which we'll load and execute as a Data URI,

  5. paste it into the formula, noting the data:application/javascript;base64, prefix:

    {!REQUIRESCRIPT("data:application/javascript;base64,KGZ1bmN0aW9...wZyIpJzsKfSgpKTs=")}
    window.location = '/apex/ns__PageName'; //button action when clicked
    

The usual caveat applies: using a Data URI here may be subject to future validation, but rest assured for now Salesforce support the use of REQUIRESCRIPT in a Custom Button. Your use is only cosmetic.

Further, if you wanted to separate the button click outcome from the pink candy polka dots, you could put the cosmetic JavaScript in a separate Custom Link which you place somewhere on the page layout. It's one novel way of running JavaScript in the scope of a standard page without needing to configure the sidebar or use a narrow Home Page Component.

  • 1
    How did you do that? – Kenn K Apr 9 '13 at 22:22
  • 4
    Black Salesforce Magician :S at roam – Rao Apr 9 '13 at 22:31
  • 8
    Woah, that is some supreme awesomeness – Ralph Callaway Apr 9 '13 at 22:38
  • 3
    Well done Professor of the Dark Arts ;) – techtrekker Apr 9 '13 at 22:39
  • 2
    Nice work herp, very, very crafty indeed :) – Phil Hawthorn Apr 10 '13 at 7:59

There is no way to declaratively modify the color of a standard button that is part of Salesforce configuration. See this other post on some crafty ways to modify the Salesforce CSS.

Can I apply a custom stylesheet to modify the look and feel of a standard object detail page?

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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