[SalesForce] Single Visualforce page to be added in two different Object Page layout

I have VF Page which needs to be added to 2 different Object's Page Layout section. I am not able to refer the VF page unless VFP's StandardController attribute refers to the Object. Is there any way to refer my common VF Page into multiple object Page layouts? I dont want to create multiple VF Pages with Same code (Only diff would be the Standardcontroller).

One Design approach is have two VFP with different Standard contoller and include my page in both the VFP.

VF Page 1
<apex:page standardController="CustomObject1__c" extensions="Controller"> 
      <apex:include pageName="commonVFPage"/>
</apex:page>


VF Page 2
<apex:page standardController="CustomObject2__c" extensions="Controller"> 
      <apex:include pageName="commonVFPage"/>
</apex:page>

Is there any other good way to approach this problem?

Best Answer

You will want to move your VF code to a VF Component Creating and Using Custom Components.

You can then create two VF pages which each include the same component (the standard controller is then on the VF Page and you can use a custom controller for your component).

This architecture will allow you to keep your code in one place but use on two standard pages.

Related Topic