I have a custom object Installation__c which is related to accounts by a master detail relation. The related list on accounts detail page lets me create and edit records for my custom object.

However for default values and picklists I need data from an external source when editing my custom object. So I need a Visualforce page to get my data via Apex or ajax.

Can I link the related list with a Visualforce page or add a Visualforce page to page layout of my custom object?


You can use the apex:detail tag, and the apex:relatedList tag to add the detail page for a record to a layout, as well as related lists associated with the object. You could add a custom component which mimics a related list to the visualforce page as well.

<apex:page standardcontroller="Account"> 
    <apex:detail relatedList="false" />
    <c:someComponent ... />
    <apex:relatedList list="Contacts" />
    <apex:relatedList list="Cases" />
    <apex:relatedList list="Opportunities" /> 

This does come with some issues- you'll have to override the existing layout for the detail view, meaning any user customizations to the order of related lists will be lost. Any future changes to the order of the related lists will need to be done with code.

You could also create a visualforce page, or a visualforce component, and add it to the detail layout for the object. If you'll need to make a callout and set some default data, this might be your best shot. You can read more about this in this related question, and in the Visualforce Workbook.

Any page with the standard controller for your object will be usable on the page layout, and you can include whatever you need on the page, such as a pre-existing component, or a related list.

<apex:page standardController="Account>
    <c:someComponent ... />
    <apex:relatedList list="contacts" />

Once you have created a visualforce page which you would like to add to your standard layout, edit the layout you would like to add the page too. Scroll down, and you'll see a list of pages you can drag & drop to the page layout.

Visualforce Drop & Drag Interface

  • Ok, now I have a Visualforce page and a custom controller for my custom class. Can you explain how to link the related list on account page to my Visualforce page (and not to the standard edit page)? I cannot see how to add the Visualforce page to the custom objects layout (there is no Visualforce option). – Obi_77 Sep 28 '16 at 15:36
  • I've added how to add a visualforce page to a page layout, with an image to help. If you still don't see it, make sure you are using the standardController attribute, set to the sObject type. – battery.cord Sep 28 '16 at 15:55
  • To link to a visualforce page from a related list, add a custom button with the url set to your visualforce page on the object type of the related list (for example, a button on a contact related list would be added to the contact object), and then set the button on the page layout, via the customize option on the related list. – battery.cord Sep 28 '16 at 15:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.