+ Start a Discussion
Chirag MehtaChirag Mehta 

How to add button on edit page (without overriding with visualforce page)?

I want to add a button on edit page of a record (say button which opens an external URL in a new window, may be a a url for reference). How do I achieve so?


There's always option of overriding with visualforce page, but there's lot of pitfalls around that approach (say a new recordtype or field is added, you need to create new visualforcce page or update the page respectively etc)

Any idea on how to achieve this? 

 

Chirag

Best Answer chosen by Admin (Salesforce Developers) 
Chirag MehtaChirag Mehta
I've found a JS trick to make this possible. This solution is going to open door for lot of things, its really amazing and working great (in almost every browser IE, FF and Chrome)

 

  • Create a Narrow HomePageComponent of type HTML
  • Select "Show HTML" and insert following script
  • <script type="text/javascript">
    var url = window.location.href;
    window.onload = function () {
    if(url.indexOf('/500')!=-1 && url.indexOf('/e')!=-1) 	
    	document.getElementById('topButtonRow').innerHTML = 
    					document.getElementById('topButtonRow').innerHTML + 
    					'<a class="btn" style="padding: 4px 3px;margin: 0 2px;text-decoration: none;" target="_blank" href="http://www.google.com">Google.com</a>';
    }
    </script>
  • Now update homepagelayout and add this HTML component
  • Above script will now show a button Google.com on CASE EDIT and CASE NEW layout
This code can be modified to do anything you desire, but needs a background of a coder :))

Please note that you can add a neat name to the HTML Section say "Welcome to Chatter" and add certain text also (along with the script), so that for the world it will be a "Messages section" and for you it will be automatically executing script.

All Answers

Chirag MehtaChirag Mehta
I've found a JS trick to make this possible. This solution is going to open door for lot of things, its really amazing and working great (in almost every browser IE, FF and Chrome)

 

  • Create a Narrow HomePageComponent of type HTML
  • Select "Show HTML" and insert following script
  • <script type="text/javascript">
    var url = window.location.href;
    window.onload = function () {
    if(url.indexOf('/500')!=-1 && url.indexOf('/e')!=-1) 	
    	document.getElementById('topButtonRow').innerHTML = 
    					document.getElementById('topButtonRow').innerHTML + 
    					'<a class="btn" style="padding: 4px 3px;margin: 0 2px;text-decoration: none;" target="_blank" href="http://www.google.com">Google.com</a>';
    }
    </script>
  • Now update homepagelayout and add this HTML component
  • Above script will now show a button Google.com on CASE EDIT and CASE NEW layout
This code can be modified to do anything you desire, but needs a background of a coder :))

Please note that you can add a neat name to the HTML Section say "Welcome to Chatter" and add certain text also (along with the script), so that for the world it will be a "Messages section" and for you it will be automatically executing script.

This was selected as the best answer
LalitLalit

Can we open a related list, or child object from this custom button in Edit page layout.

 

We have a custom object say Sales form, on edit apge of customer object we need to add a button say Save and Add Product(similar to One we can have on Opportunity page). User forget to add Product/SKU after saving the sales form

 

New Button(Save and Add product), will save the sales-form first and then depends on record type will open the related list(child object).

Say a Sales form is for Custom Program, after save,. it will open up Custom Program relate list.

If Record type is of Price Change Notification it willl open up related list of SKU detail..

 

Is this possible, please adivse, we have 9-10 different record type, and we don't want to re-write the application with visualforce and all customization.

 

skausskaus

Hey Chirag,

 

I tried your script and it totally works.. This def opens up door to do a LOT of customizations on the page behavior.. But isn't this kind of hacking ?

And my only fear is if Salesforce finds out and closes this loophole , the script will stop working one day.  I feel Salesforce page is vulnerable !!

 

But cool work man.. I am afraid my architect might just freak out to see something like this :)

Chirag MehtaChirag Mehta

Yes it open LOT of customizations on page behavior. Salesforce doesn't allow it neatly, so we tweaker have to search such ways of doing it. But obv these are not solutions, they are hacks and can stop working any day. So better to inform the same to client when delivering using these approaches, that its a tweak and might not work with salesforce releases.

faceroy123faceroy123

Chirag,

 

How do I add onclick functionality to this button based on a field within the case?

 

Thanks

 

 

AshishyadavAshishyadav

No its not working now..... it only shows javvasciprt code or sometimes nothing

Alexis IglauerAlexis Iglauer

This looks really useful, but I am having trouble getting it to work.  The code only seems to embed in the sidebar on the home page, and I actually need it on the Opportunity page -- how can one make this work?

 

Thanks

Sujan Kumar ReddySujan Kumar Reddy
Hi Chirag,

I just had the similar requirement from my client today. i tried with your work around. Code snippet works Perfectly! Configured the same in my sandbox. But due to this code, List views are not getting loaded. It is showing as "Loading...." But it never comes. Once we delete the same button, then it would become normal. Did anyone faced the similar issue. If so, then what is work around for this.

Please suggest.
Chirag MehtaChirag Mehta

Seems the script destroys existing onload events.


I created a modification that will keep the existing onload events as is. I removed the timeout too; the onload event will fire after all elements are loaded, so tineout is not necessary:

Read more: Salesforce – Hide standard buttons display (Working version) http://www.chiragmehta.info/chirag/2010/08/16/salesforce-hide-standard-buttons-display-working-version/#ixzz2fMk4GFT6 

mpatilmpatil
Hi How Do I add this button to the edit page of Lead? ANyone did anything similar?
Krishna1317Krishna1317
I am having same issues as @Alexis Iglauer. Do anyone have solution?
Krishna BandiKrishna Bandi
Hi Chirag,

Could you please post the updated Java Script.
Jose GuevaraJose Guevara
It seems that this hack is not available anymore. Check this:
http://docs.releasenotes.salesforce.com/en-us/summer14/release-notes/rn_forcecom_home_page_components.htm
As far as I see, it is not possible to set html or javascript code in the Home Page components since Summer '14 works with the new Rich Text editor.
DilipRathoreDilipRathore
Hi Chirag,

Could you please upload a working version of the code for this.

Regards
Miguel A. SantanaMiguel A. Santana
Hi Chirag, Has you notice if it stop working for you after the Salesforce.com Summer ’14 Release? DilipRathore aslo posted recently asking for the updated code so I am not sure it it still works.  Can you please let the community know before trying it?
chvl narayanachvl narayana
HI Chirag,

I tried to do in my Dev org, but I am not able to see this button, could you please suggest met Where I did wrong.