1

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 2

3

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);
}
1
  • Is this the only way by using extension..! no other possible way is available other than this.
    – Lovel_leo
    Commented Apr 22, 2016 at 12:28
3

You have to use standard controller and have your custom code in extension class. FYI There is standard controller for custom object.

1
  • Please mark as best answer if it solve your issue.
    – Rachit
    Commented Apr 22, 2016 at 6:04

You must log in to answer this question.

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