1

I have 5 record types, I want to display different page layouts for different record Types while overriding the standard "New" button. Instead of writing each page block for each Page layout( record Types) how can do this give me some idea?

Apex:

public with sharing class Rfleet_ServiceCustomNew_EXT {
public String selectedvalue{get;set;}
public selectoption[] myoptions{set;get;}
public String strOppid{get;set;}
public String strModelCode {get;set;}
public String strVersionCode {get;set;}
public String strop{get;set;}
public String strgetvalue{get;set;}
List<String> lstC2Goptions= new List<String>();
public Service__c objService{get;set;}
public boolean showBlock{get; set;}
public boolean showStandardBlock{get; set;}
public List<SelectOption> lstOptions {get; private set;}
public Map<String,Double> mapOptionCodePrice = new Map<String,Double>();
public Rfleet_ServiceCustomNew_EXT(ApexPages.StandardController std) {
    objService = new Service__c();
    objService = (Service__c) std.getRecord();
    strOppid= objService.Opportunity_car_set__c;
    objService.Opportunity_car_set__c=strOppid;
    if(strOppid!=null){
        showBlock=true;
        system.debug('<<<<<<str<<'+strOppid);
        Opportunity_car_set__c opp=[SELECT Model__r.ProductCode,Version__r.Rfleet_C2G_version_code__c FROM Opportunity_car_set__c where id=:strOppid];    
        strModelCode    = opp.Model__r.ProductCode;
        strVersionCode  = opp.Version__r.Rfleet_C2G_version_code__c;
    }
    else{showStandardBlock=true;} 
    Rfleet_DZC2GOptionDetails_CLS optionValue=new Rfleet_DZC2GOptionDetails_CLS();
    if(String.isNotBlank(strModelCode) && String.isNotBlank(strVersionCode)) {
        lstC2Goptions=optionValue.getPriceListbasedOnReference(strModelCode,strVersionCode);
    }
    if(lstC2Goptions.size()>0){
        lstOptions = new List<SelectOption>();
        lstOptions.add(new SelectOption('','--Select--'));
        for(String strC2Goptions:lstC2Goptions){
            lstOptions .add(new SelectOption(strC2Goptions,strC2Goptions));
         }
     }
 }

public void assignValue(){strop=objService.CodeC2G__c;}
Public PageReference customSave(){
    String strCode = strop.substring(0,strop.indexOf('-'));
    Double dbPriceHT;
    Rfleet_DZC2GOptionDetails_CLS optionValues =new Rfleet_DZC2GOptionDetails_CLS();     
    mapOptionCodePrice = optionValues.getOptionPrice(strModelCode,strVersionCode);
    if (mapOptionCodePrice.containsKey(strCode)) {
        system.debug('## strcode is available inside mapOptionCodePrice ##');
        dbPriceHT = mapOptionCodePrice.get(strCode);
    }
    system.debug('## dbPriceHT  is..::'+ dbPriceHT);
    if (dbPriceHT!=null) {
        objService.Price_HT__c=dbPriceHT;
    }   
    try{
        insert objService;
        return new Pagereference ('/'+objService.Id);
    }
    catch(Exception ex){
        System.debug('Error in SOQL Fetching'+ex);
        ApexPages.Message msg = new ApexPages.Message(Apexpages.Severity.ERROR, ex.getMessage() );
        ApexPages.addMessage(msg);
        return null;
    }
}

  }

VF:

<apex:page standardController="Service__c" extensions="Rfleet_ServiceCustomNew_EXT" sidebar="true">

    <apex:sectionheader title="{!$ObjectType.Service__c.label} Edit" subtitle="{!IF(ISNULL(Service__c.Name), 'New Service',Service__c.Name)}"/>
    <apex:form >
   <style>
   .errorMsg{display:none !important;}
   </style>
    <!-- **********   Standard Service from Tab   **********  -->

    <apex:pageblock mode="edit" title="{!$ObjectType.Service__c.label}Edit" rendered="{!showStandardBlock}">
         <apex:pageMessages id="showmsg" escape="false"></apex:pageMessages>
                <apex:pageblockbuttons >
                    <apex:commandbutton value="Save" action="{!Save}"/>
                    <apex:commandbutton value="Cancel" action="{!Cancel}"/>
                 </apex:pageblockbuttons>

                <apex:pageblocksection title="Information" showheader="true" columns="2">
                        <apex:inputfield value="{!objService.Service_Type__c}" required="false"/>
                        <apex:inputfield value="{!objService.CurrencyIsoCode}" required="false"/>
                        <apex:inputfield value="{!objService.Simple_service_type__c}" required="false"/>
                        <apex:inputfield value="{!objService.Price_HT__c}" required="false"/>
                        <apex:inputfield value="{!objService.Type_Service_Entered_by_user__c}" required="false"/>
                        <apex:inputfield value="{!objService.Quantity__c}" required="false"/>
                        <apex:inputfield value="{!Service__c.Code__c}" required="false"/>
                        <apex:inputfield value="{!objService.Unitary_Price__c}" required="false"/>
                        <apex:inputfield value="{!objService.Label__c}" required="false"/>
                        <apex:pageblocksectionitem />
               </apex:pageblocksection>

                <apex:pageblocksection title="Opportunity Car Set (Algeria)" showheader="true" columns="2">
                    <apex:inputfield value="{!objService.Opportunity_car_set__c}" required="false"/>
                    <apex:pageblocksectionitem />
                </apex:pageblocksection>

                <apex:pageblocksection title="Order Car Set" showheader="true" columns="2">
                    <apex:inputfield value="{!objService.Car_Set__c}" required="false"/>
                    <apex:inputfield value="{!objService.CB_Services_Repository__c}" required="false"/>
                    <apex:inputfield value="{!objService.Discount__c}" required="false"/>
                    <apex:inputfield value="{!objService.CB_Options_repository__c}" required="false"/>
                    <apex:inputfield value="{!objService.Discount_Amount__c}" required="false"/>
                    <apex:inputfield value="{!objService.Simple_Product__c}" required="false"/>
                    <apex:inputfield value="{!objService.User_Discount__c}" required="false"/>
                    <apex:inputfield value="{!objService.Customer_Sales_Price_HT__c}" required="false"/>
                </apex:pageblocksection>
        </apex:pageblock>



<!-- **********  Related List Service  **********  -->



    <apex:pageblock mode="edit" title="{!$ObjectType.Service__c.label}Edit" rendered="{!showBlock}">
             <apex:pageMessages id="showmsg" escape="false"></apex:pageMessages>
            <apex:pageblockbuttons >
                <apex:commandbutton value="Save" action="{!customSave}" />
                <apex:commandbutton value="Cancel" action="{!Cancel}"/>
             </apex:pageblockbuttons>

              <div class = "slds" style="clear:both;overflow:hidden;height:auto;width:125%;"> 
                <apex:pageblocksection title="Information" showheader="true" columns="2">
                        <apex:inputfield value="{!objService.Service_Type__c}" required="false"/>
                        <apex:inputfield value="{!objService.CurrencyIsoCode}" required="false"/>
                        <apex:inputfield value="{!objService.Simple_service_type__c}" required="false"/>
                        <apex:inputfield value="{!objService.Price_HT__c}" required="false"/>
                        <apex:inputfield value="{!objService.Type_Service_Entered_by_user__c}" required="false"/>
                        <apex:inputfield value="{!objService.Quantity__c}" required="false"/>
                        <apex:inputfield value="{!Service__c.Code__c}" required="false"/>
                        <apex:inputfield value="{!objService.Unitary_Price__c}" required="false"/>
                        <apex:inputfield value="{!objService.Label__c}" required="false"/>
                        <apex:selectList size="1" value="{!objService.CodeC2G__c}" >
                        <apex:selectOptions value="{!lstOptions}"> </apex:selectOptions>
                        <apex:actionSupport event="onchange" action="{!assignValue}" reRender="a" />
                        </apex:selectList>
                        <apex:inputHidden value="{!objService.Code__c}" id="codeFieldId"/>
                       <apex:pageblocksectionitem />
               </apex:pageblocksection>
                </div>

                <apex:pageblocksection title="Opportunity Car Set (Algeria)" showheader="true" columns="2">
                    <apex:inputfield value="{!objService.Opportunity_car_set__c}" required="false"/>
                    <apex:pageblocksectionitem />
                </apex:pageblocksection>

                <apex:pageblocksection title="Order Car Set" showheader="true" columns="2">
                    <apex:inputfield value="{!objService.Car_Set__c}" required="false"/>
                    <apex:inputfield value="{!objService.CB_Services_Repository__c}" required="false"/>
                    <apex:inputfield value="{!objService.Discount__c}" required="false"/>
                    <apex:inputfield value="{!objService.CB_Options_repository__c}" required="false"/>
                    <apex:inputfield value="{!objService.Discount_Amount__c}" required="false"/>
                    <apex:inputfield value="{!objService.Simple_Product__c}" />
                    <apex:inputfield value="{!objService.User_Discount__c}" required="false"/>
                    <apex:inputfield value="{!objService.Customer_Sales_Price_HT__c}" required="false"/>
                </apex:pageblocksection>
        </apex:pageblock>

    </apex:form>
</apex:page>

Thanks in advance!!

4
  • Just to be clear, you want to show different set of fields on the VF page for different record types?
    – AslamK
    Commented Mar 8, 2016 at 5:24
  • create a single page and in that page check recordtype and based on that redirect to different pages. Commented Mar 8, 2016 at 5:25
  • 1
    @TusharSharma I think that is what she does not want to do. She wants to create just one page. So I think she can use "rendered" attribute on the different sections/fields to show/hide depending on the record type.
    – AslamK
    Commented Mar 8, 2016 at 5:27
  • [email protected] want to use rendered attribute on different fields to show/hide depending on the record type
    – uma451
    Commented Mar 8, 2016 at 5:31

1 Answer 1

1

Just an example

In your controller

take a variable that store the one recordType Id

List<RecordType> lstRecordTypeSomething {get; private set;}
List<RecordType> lstRecordTypeSomething1 {get; private set;}

in you constructor

query on RecordType

lstRecordTypeSomething = [SELECT Id FROM RecordType 
                           WHERE SobjectType = 'Service__c' 
                             and DeveloperName = 'Something' ];
lstRecordTypeSomething1 = [SELECT Id FROM RecordType 
                            WHERE SobjectType = 'Service__c' 
                              and DeveloperName = 'Something1' ];

Now in VF page check

If you want to display below field only for

<apex:inputfield value="{!objService.Service_Type__c}" required="false" 
rendered = '{!(lstRecordTypeSomething[0].Id == objService.RecordTypeId)}'/>

If you want to display for both record Type then use OR conditions.

<apex:inputfield value="{!objService.Service_Type__c}" required="false" 
  rendered = '{!OR(lstRecordTypeSomething[0].Id == objService.RecordTypeId,
                   lstRecordTypeSomething1[0].Id == objService.RecordTypeId)}'/>

You must log in to answer this question.

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