function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Creating a button to pass account information to new custom object

If I am not mistaken there is a way to create a Javascript button to pass info into a new custom object when you create a new form.


I have a custom object that has a lookup to the Opporunity, so when I create the new form it automatically fills that info in.  Howver, I would like it to also fill in the account and the bill to.  I am not sure how to do this, I think you can hack the URL but not sure how to do this.  I looked online, but don't exactly understand the quick info.  Thanks in advance.

Cory CowgillCory Cowgill



The best way to do this is to create a custom Visualforce Page to do this.


1. Create a new Apex Class "CUstomController". The constructor should take ApexPages.standardPage so you can overwrite the standard new page with VF Page.

2. Create a new VF Page call it "CUstomObjectNewPage"

3. VF Page should have "<apex:page standardController="CustomObject__c" extensions ="CustomController"

4. In the constructor you should have access to the Account and Bill ID's or Information, which you can use to populate the Record.

5. Overwrite the NEW button on the custom object with your VF Page.


Though creating a VF is an option, I would also want you to consider using a Trigger to populate the Account Name and the Bill To. I believe if you write a VF page, you may lose out on a lot of standard functionality and would end up doing it custom.

You may want to consider writing a BEFORE INSERT trigger, which will populate these fields when you create a new record into the custom object, based upon the Opportunity.

Hope this helps!

I ended up creating a button w a URL and passed the info, it was pretty easy once I understood what exactly to do. Thanks for the great options