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!!