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.

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);
}
| improve this answer | |
  • Is this the only way by using extension..! no other possible way is available other than this. – Lovel_leo Apr 22 '16 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.

| improve this answer | |
  • Please mark as best answer if it solve your issue. – Rachit Apr 22 '16 at 6:04

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.