Find your content:

Search form

You are here

How can I execute JavaScript on a SFDC Standard Detail Page?


*NOTE: This is not feasible as of the latest SFDC Releases. *

I have a requirement to execute some JavaScript on a SFDC Standard Detail page.

Specifically we would like to remove the ability for the users to add Notes to an object, but still retain the ability to add Attachments.

You cannot remove the button from the Notes & Attachments related list via standard declrative features (Page Layouts, etc). We would like to remove the "New Note" button, as well as rename the Related List to "Attachments".

I know I could do this in JavaScript by editing the DOM. Is there a way I can run JavaScript in a standard SFDC detail page?

Attribution to: CoryCowgill

Possible Suggestion/Solution #1

I have come up with an addition to @bigassforce 's solution to running code on a page that makes it a bit neater.

  1. Define your javascript eg(this example changes the size of a custom component)

    (function() {
    var imageFrames = document.getElementsByTagName('iframe');
    for (var i = 0 ; i < imageFrames.length ; i++){
      if (imageFrames[i].title = 'Account Image'){
       imageFrames[i].height = 120;
  2. Base64 encode this and put in button as described by @bigassforce here

  3. Make another script (this one runs on a settimeout function) that removes the button or link! (I used a link, but I don't think it matters). This means that your first block of code will run and do what you want it to do and your second block will clean up. No messy buttons left lying around or extra code in buttons that is not associated with the functionality of that button itself.

I've called the link "System Functions" so make sure you modify the code to account for whatever you call the button. This code will work for links, but you'll have to work out the structure of the html if you want to remove custom buttons.

Removal code:

setTimeout(function() {
    var table = document.getElementsByClassName('customLinks');
    if (!table.length){
    var anchorTags = table[0].getElementsByTagName('a');
    for (var j = 0 ; j < anchorTags.length ; j++){
        if (anchorTags[j].innerText == "System Functions"){
}, 5000);

Attribution to: Caspar Harmer

Possible Suggestion/Solution #2

You can do this with either javascript or css. Create a visualforce page and include it as a part of the page layout. The visualforce page should contain a script or style tag to manipulate the standard page.

Attribution to: Phil Rymek

Possible Suggestion/Solution #3

I've done this with a sidebar component. There is an almost equal howto on this subject created by another developer (theNrd):

Check this out, should get you started.

Attribution to: Erik Kramer

Possible Suggestion/Solution #4

Start by creating a VF page that includes the dialog, and uses the standard controller so you can drop it into the object's whose details your trying to add it to the page layout, since you didn't specify, I'll just use 'Account'

You need to uploaded your jQuery or whatever JS libraries your using to generate the dialog into a static resource file (as you can't remotely use a CDN on the standard details page)

<apex:page standardController="account">
<apex:includeScript value="{!URLFOR($Resource.jquery)}" />
<script type="text/javascript">
        alert('hello world');

<button id="open-notes-dialog">Add notes</button>

Add the page to the layout of your details page. Unfortunately, its kind of hard to get it to display in a correct size.

However, you will now have this VF page in an iFrame and with some creative JS can go outside of your iframe (into the parent) and rename the 'Notes & Attachments' heading, and add your dialog!

Update -- looks like you can't access static resources from the standard details page- so maybe add the javascript you need to your page statically but adding a dynamic library might be limited.

Attribution to: jordan.baucke

Possible Suggestion/Solution #5

The only way we found to insert code directly into the DOM of any Salesforce page is via a Home Page Component (Setup > Customize > Home > Home Page Components).

Create a New Custom Component, Type = HTML Area. In the editor, check the "Show HTML" checkbox in the upper right. You can then put in arbitrary HTML and JavaScript and it can traverse the DOM.

If you just want your code on a single page, create a "Wide (Right) Column" component and add it to your page layout.

If you want the code to run on every* page in SFDC, then you'll want to put it into a "Narrow (Left) Column" (often referred to as the sidebar) component, check the Setup > Customize > User Interface > Show Custom Sidebar Components on All Pages checkbox, and finally select it in Setup > Customize > Home > Home Page Layouts > your layout.

Home Page Components don't need to have any visible UI.

  • Chatter pages don't have the sidebar, so this won't work there. The Service Cloud Console also doesn't show the sidebar and has no equivalent, so you can't do this there either.

Attribution to: Rajat Paharia

Possible Suggestion/Solution #6

Another approach to this problem is to load your JavaScript using the {!REQUIRESCRIPT} function in a custom button/link on the page.
More info here: Changing the color of a custom button

Attribution to: Scott McClung
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content