How to map a Visualforce page to an object's layout which is using custom controller. As I have seen if you use standard controller then only you can map visualforce to the page layout. But what to do when we have custom controller in Visual Page and wants to map it object's layout.
2 Answers
here it is a small example.
ApexPage:
<apex:page standardController="Custom__c" extensions="CustomController" showHeader="true" sidebar="true">
</apex:page>
ApexController:
public with sharing class CustomController {
public CustomController(ApexPages.StandardController controller) {
Id standardId = controller.getId();
}
}
ApexTestClass:
@isTest
private class CustomControllerTest {
@isTest static void test_controller() {
ApexPages.StandardController controller = new ApexPages.StandardController(new Custom__c());
CustomController ctrl = new CustomController(controller);
}
-
Is this the only way by using extension..! no other possible way is available other than this. Commented Apr 22, 2016 at 12:28
You have to use standard controller and have your custom code in extension class. FYI There is standard controller for custom object.