2

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.

https://cs17.salesforce.com/a0Q/e?
CF00Ng0000000TpGb%3D{!Opportunity.Name}&
CF00Ng0000000TpGb_lkid%3D{!Opportunity.Id}&
retURL=%2F{!Opportunity.Id}&
RecordType=012g0000000Cjr9&
ent=01Ig0000000CqPF&
CF00Ng0000000TwBE_lkid={!Account.Id}&
CF00Ng0000000TwBE={!Account.Name}

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):
CF00Ng0000000TpGb%3DUTP+OnDemand+%282013-04-12%29&

From STANDARD button:
CF00Ng0000000TpGb%3DUTP%2BOnDemand%2B%25282013-04-12%2529%26

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 =).

https://cs17.salesforce.com/a0Q/e?
CF00Ng0000000TpGb={!Opportunity.Name}&
CF00Ng0000000TpGb_lkid={!Opportunity.Id}&
retURL=%2F{!Opportunity.Id}&
RecordType=012g0000000Cjr9&
ent=01Ig0000000CqPF&
CF00Ng0000000TwBE_lkid={!Account.Id}&
CF00Ng0000000TwBE={!Account.Name}

--- Update 3 ---

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

/setup/ui/recordtypeselect.jsp?
retURL=%2F{!Opportunity.Id}&
ent=01Ig0000000CqPF&
save_new_url=
%2Fa0Q%2Fe%3F
CF00Ng0000000TpGb%3D{!Opportunity.Name}%26
CF00Ng0000000TpGb_lkid%3D{!Opportunity.Id}%26
CF00Ng0000000TwBE_lkid%3D{!Account.Id}%26
CF00Ng0000000TwBE%3D{!Account.Name}%26
retURL%3D%2F{!Opportunity.Id}

3 Answers 3

2

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.

http://raydehler.com/cloud/clod/salesforce-url-hacking-to-prepopulate-fields-on-a-standard-page-layout.html

https://stackoverflow.com/questions/5334585/custom-button-to-copy-data-from-opportunity-into-a-related-custom-object

https://success.salesforce.com/questionDetail?qid=a1X30000000dahDEAQ

4
  • 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
    Commented 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
    Commented 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
    Commented 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
    Commented May 9, 2014 at 7:35
1

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:

/a0F/e?CF00NG0000009bO2L={!Opportunity.Name}&CF00NG0000009bO2L_lkid=006G000000KcwcU&retURL=%2F006G000000KcwcU&CF00NG0000009bO2Q={!Opportunity.Account}

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

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

Hope it helps!!

3
  • 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
    Commented 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
    Commented 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
    Commented Apr 29, 2013 at 17:37
0

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:

http://www.salesforce.com/docs/developer/cookbook/Content/vf_override_button.htm

1
  • Perhaps you could look at Update 1 in my original question text and give some insight if you have any? :-/ Thanks.
    – AMM
    Commented 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 .