function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
mustapha L 1mustapha L 1 

VisualForce, Display 1 layout based on Object criteria

Hi there !
I have created many layouts with VisualForce.
I have created a BUTTON which fired one of Layouts.

what i'm looking for is how to make kind of auto-select Layout.

idea is to create one customField where are listed some criteria and based on those criteria when we clic on Button automatically the most approproated page will be displayed.
I already have Layout, button, criteria...i just need assistance about how to fire one or another visual page 

exemple : we could image a custom Field named "language" and based on this field it will open the FR , UK...or SPANISH layout.

Many thanks for assistance you could provide.
pconpcon
you can do this a couple of different ways.  You could create a single large Visualforce page which hides / shows the layout based on your custom field using the rendered attribute.  Another option would be to put each of your layouts into tabs using the apex:tab tag and then select the active tag based on your criteria.  And yet another option would be to have a Visualforce page for each of your layouts and then have one main page that automatically redirects the user to the correct child page.  For example:
 
<apex:page standardController="Contact" extensions="ContactLangPicker" action="{!bouncePage}">
</apex:page>
 
public class ContactLangPicker {
    public Contact c;

    public static Map<String, String> LANG_MAP = new Map<String, String>{
        'English' => '/apex/EnglishContact',
        'French' => '/apex/FrenchContact',
        'Esperanto' => '/apex/EsperantoContact'
    };

    public ContactLangPicker(ApexPages.StandardController stdController) {
        this.c = (Contact) stdController.getRecord();
    }

    public PageReference bouncePage() {
        String url = !LANG_MAP.containsKey(this.c.Language__c) ?
            LANG_MAP.get('English') :
            LANG_MAP.get(this.c.Language__c);
        PageReference p = new PageReference(url);
        p.getParameters().put('Id', this.c.Id);
        return p;
    }
}