[SalesForce] Standard Button CODE Available

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}

Best Answer

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

Related Topic