How to Change Custom Button Color in Salesforce?

How to Change Custom Button Color in Salesforce?

On May 18, 2025, Posted by , In Salesforce, With Comments Off on How to Change Custom Button Color in Salesforce?
How to Change Custom Button Color in Salesforce

Customizing the appearance of a custom button in Salesforce, particularly those created under Custom Buttons and Links on an object, is not supported natively. However, there are creative methods you can use to modify the button’s color or style. These methods involve JavaScript and require embedding code within the button configuration.

Using JavaScript to Alter Custom Button Color

To change the color of a custom button, you can use JavaScript in a Detail Page Button with the behavior set to Execute JavaScript. Here’s how you can implement this solution:

Unlock your potential with expert-led Salesforce Training in Dallas, combining practical skills and certification. Advance your career and master the dynamic Salesforce platform..!!

  1. Navigate to Setup > Object Manager > [Your Object] > Buttons, Links, and Actions.
  2. Click New Button or Link.
  3. Select Detail Page Button and set the behavior to Execute JavaScript.
  4. Use the following JavaScript code to change the button’s background:
(function() {
  var button = document.getElementsByName('your_button')[0];
  if (button) {
    button.style.backgroundColor = '#ff69b4'; // Set to pink color
    button.style.color = '#ffffff'; // Optional: Change text color
    button.style.border = '1px solid #ff1493'; // Optional: Add border
  }
})();

Replace your_button with the actual name of your button in lowercase. Adjust the color codes to suit your design.

Encoding JavaScript as a Data URI

For a more compact and embedded approach, encode the JavaScript using Base64 encoding and include it in the button using REQUIRESCRIPT. This ensures the JavaScript is self-contained.

Example:

  1. Encode the following script using a Base64 encoder:
(function() {
  var button = document.getElementsByName('your_button')[0];
  button.style.backgroundColor = '#ff69b4'; // Change background to pink
})();
  1. Add the encoded script to the button formula like this:

If you want to separate the styling logic from the button’s functionality, you can create a Custom Link to apply the cosmetic changes. Place this link on the page layout, and it will execute the styling JavaScript.

Example:

  1. Go to Custom Links in the object setup.
  2. Create a new link with the following JavaScript:
(function() {
  var button = document.getElementsByName('your_button')[0];
  button.style.backgroundColor = '#32cd32'; // Set green background
})();
  1. Add this custom link to your page layout.

Key Considerations

  1. Browser Support: These methods rely on the browser executing JavaScript correctly. Test across different browsers to ensure consistency.
  2. Salesforce Validation: Salesforce might restrict such customizations in future updates, especially the use of REQUIRESCRIPT.
  3. Cosmetic Changes Only: These techniques modify appearance but do not provide deeper functionality.

By following these methods, you can effectively change the color and style of custom buttons, enhancing the visual appeal and user experience in Salesforce.

See also: Detecting Salesforce1 vs. Desktop in Visualforce Pages

Summing Up

Changing the color of a custom button in Salesforce, especially those created under Custom Buttons and Links, requires creative solutions like using JavaScript. By embedding JavaScript in a Detail Page Button or using Base64-encoded scripts with REQUIRESCRIPT, you can modify the button’s appearance. Another option is to implement a Custom Link to apply the styling separately. Although these methods work, they are primarily cosmetic and may be subject to future validation by Salesforce, so it’s important to test them thoroughly across different environments and browsers.

CRS Info Solutions offers an immersive Salesforce Training in Dallas, designed specifically for beginners, guiding you through each phase of your learning path. This hands-on course blends real-world applications with strong conceptual foundations, ensuring a clear and practical understanding of Salesforce. You will benefit from resources such as daily notes, interactive video lessons, and focused interview preparation, providing you with the expertise and confidence to pass Salesforce certifications and take your career to the next level.

As a leading provider in Salesforce education, CRS Info Solutions covers a wide range of modules, including Admin, Developer, Integration, and Lightning Web Components (LWC). Their experienced instructors deliver a balanced mix of theoretical knowledge and practical training, bridging the gap between classroom learning and real-world implementation. The course is carefully crafted to meet industry demands, helping learners build solid foundations and apply their skills in actual work environments. With a curriculum that is career-oriented and built for excellence, CRS Info Solutions ensures you are ready to meet the expectations of top employers and succeed in a competitive job market.

Discover their Salesforce program today and get started with a free demo to begin your journey toward professional achievement..!!

Comments are closed.