I have a custom object BillingInformation which has a lookup to Account. It appears as a related list on the account page. I also have a button "New Billing Information" on this related list, which opens a visualforce page I have written for creating new BillingInformation objects. So, a person on an Account page can click "New Billing Information" associated with that account.

However, when the New Billing Information page opens, the "Account" field is blank. I would like the Account field to be pre-filled with the Account I just navigated from. How can I accomplish this using VisualForce and Apex?

I'm using a custom controller - Not a controller extension.

  • Did you try passing is the Account ID as part of a URL parameter then setting that value in the controller
    – Eric
    Feb 23, 2015 at 22:46
  • I'm new to Salesforce. How can I pass the account ID when the New Billing Information button is clicked? This sounds like a good idea. Feb 23, 2015 at 22:48

1 Answer 1


In your button add a parameter for the account ID

i.e. ?acctID={!Account__c}

In your controller get the value of the parameter:

ID accID = apexPages.currentPage().getParameters().get('acctID');

Then assign it to the field of the object in your controller



public YOURCONTROLLER(ApexPages.StandardController con){

     ID accID = apexPages.currentPage().getParameters().get('acctID');
     OBJECT rec = (OBJECT)con.getRecord();
     rec.Account__C = accID;


You must log in to answer this question.

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