[SalesForce] Custom Related List and Visual Force Page

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?

Best Answer

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" /> 
</apex:page>

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" />
</apex:page>

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