Is there a repository of the actual code behind Standard Buttons? Specifically, I'm looking for the code for "New" (and in my case, it's for use within a Related List on Opportunity).

I want to replicate this code and "simply" add to it a reference to the Account (so that my custom object can be shown as a Related List not only on Opp, but Account, without having to manually link to the Account after clicking "New").

My searches so far have yielded no results. Basically we're talking about a button at the top of the Related List that would mimic "New", so it would create a record in the custom object, relate it to the Opp, and then ALSO relate it to the Opp's Account in a second field.

Any ideas? Is there perhaps some canned JavaScript code that does this that I can pull and learn from?

enter image description here

--- UPDATE 1 ---

This is the URL I came up with, but I'm having issues with it.


Strangely, I'm not getting the Opportunity Name using this code. I've double checked the Source on the EDIT page that the button takes me to. I do note the following discrepancy when comparing the Opportunity variables on the URL versus those from the Standard "New" button:

From MY CUSTOM button (code above):

From STANDARD button:

The name of the Opportunity is "UTP OnDemand (2013-04-22)", and I see that STANDARD is encoding the plusses, and also referencing the parentheses with an added "25" in front (%2528 and %2529). How can I account for this when all I'm doing is referencing SF variables in my URL??

--- UPDATE 2 ---

This is the WORKING code (replaced %3D with =).


--- Update 3 ---

Code now used (so I don't have to make copies for each Record Type, or adjust URL for Sandbox/Production):


3 Answers 3


I don't think there is a repository as such but you can examine what a standard button does by looking at the page source or at the URL upon firing the action.

All you would need to do in this case is to pass the account id as a parameter in the URL. There are many resources online that explain how to do this.




  • Thanks for the very helpful links. I have one lingering problem hopefully you or someone can assist with, detailed in "UPDATE 1" in my original question. SF is being queer about encoding special characters...
    – AMM
    Apr 29, 2013 at 16:39
  • 1
    I have one suggestion, remove the domain part from the URL, this is not required and will ensure that your button works for sandbox or production without making any modifications. You can simply use "/a0Q/e?...." Also, take a look at the URLEncode function to encode any special characters.
    – PepeFloyd
    Apr 29, 2013 at 21:19
  • What is that first bit of the URL, e.g. '/a0Q/e?... what is the a0Q? If this is hardcoded, will that break when deploying to another org?
    – user6861
    May 8, 2014 at 15:41
  • @JohnGaughan:That is the object prefix, every object (or most objects) have a prefix, you can easily identify it in the ID of a record of that object. This should never change unless you decide to delete and recreate the object.
    – PepeFloyd
    May 9, 2014 at 7:35

Instead of a VF page you can use a custom button and pass account value thru URL. Something like below:

  1. Click on existing "New" button from the opportunity related list
  2. Copy the URL and paste it into the custom button code field
  3. Replace/add Ids of the fields and values you want to assign.

It would something like this:


00NG0000009bO2L = Id of opportunity lookup field on your custom object.

00NG0000009bO2Q = Id of Account lookup field on your custom object

Hope it helps!!

  • Thanks very much - I posted UPDATE 1 right when you were posting this. Perhaps you'll have some insight, as I'm "there" yet SF is being queer about encoding some characters...
    – AMM
    Apr 29, 2013 at 16:41
  • 1
    I updated my opportunity with the name you provided, it seems to work fine. Can you replace "%3D" with "=" and try?
    – Sai
    Apr 29, 2013 at 16:46
  • Very fascinating. Replacing the $3D actually fixes it (and still has the shorter version of the "Name" that I recorded in Update 1). Interesting. But it's fixed. Thanks for the assist!
    – AMM
    Apr 29, 2013 at 17:37

The simplest way to do this is to override a standard "New" button on the standard/custom object. There are a lot of examples/tutorials. Some of them:


  • Perhaps you could look at Update 1 in my original question text and give some insight if you have any? :-/ Thanks.
    – AMM
    Apr 29, 2013 at 16:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .