I have a custom object called Service__c . When creating "New" Service Record, for the 'RFLEET_Option_OPP' record type only I want to override the standard Page. For other Record types the Standard Page remains. Here my code:
Apex:
public class Demo_EXT{
String sRetURL = System.currentPageReference().getParameters().get('sRetURL');
String strRecordId;
public String strDevName;
public Demo_EXT(ApexPages.StandardController std) {
strRecordId = std.getId();
//system.debug('>>>>>>>>sRecordId '+strRecordId);
}
public PageReference urlRedirect() {
String strServiceRecType = ApexPages.currentPage().getParameters().get('RecordType');
system.debug('>>>>>>>>strServiceRecType '+strServiceRecType );
if (strRecordId == null && strServiceRecType != null){
strDevName='';
try {
strDevName= [Select Id, Name, DeveloperName from Recordtype WHERE SObjectType = 'Service__c' and Id = :strServiceRecType ].DeveloperName;
system.debug('>>>>>>>>strDevName'+strDevName);
}catch (QueryException e){
System.debug('Error' + e);
}
if (strDevName== 'RFLEET_Option_OPP'){
system.debug('>>>>>>>>Inside if strDevName'+strDevName);
return new PageReference('/apex/DemoVF?RecordType='+strServiceRecType );
}
else {
system.debug('>>>>>>>>Inside else'+strDevName);
return new PageReference('/a0G/e?sRetURL=%2Fa0G%2Fo&RecordType=012580000000PIb&ent=Service__c&nooverride=1');
}
}
return null;
}
}
VF:
<apex:page standardcontroller="Service__c" extensions="Demo_EXT" action="{!urlRedirect}">
<apex:messages />
<apex:sectionheader title="{!$ObjectType.Service__c.label} Edit" subtitle="{!IF(ISNULL(Service__c.Name), 'New Service',Service__c.Name)}"/>
<apex:form >
<apex:pageblock mode="edit" title="{!$ObjectType.Service__c.label} Edit">
<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="{!Service__c.Name}"/>
<apex:outputfield value="{!Service__c.OwnerId}"/>
<apex:inputfield value="{!Service__c.Service_Type__c}" required="false"/>
<apex:inputfield value="{!Service__c.CurrencyIsoCode}" required="false"/>
<apex:inputfield value="{!Service__c.CB_Services_Repository__c}" required="false"/>
<apex:inputfield value="{!Service__c.Price_HT__c}" required="false"/>
<apex:inputfield value="{!Service__c.CB_Options_repository__c}" required="false"/>
<apex:inputfield value="{!Service__c.Customer_Sales_Price_HT__c}" required="false"/>
<apex:inputfield value="{!Service__c.Code__c}" required="false"/>
<apex:inputfield value="{!Service__c.Quantity__c}" required="false"/>
<apex:inputfield value="{!Service__c.Label__c}" required="false"/>
<apex:pageblocksectionitem />
</apex:pageblocksection>
<apex:pageblocksection title="Order Car Set" showheader="true" columns="2">
<apex:inputfield value="{!Service__c.Car_Set__c}" required="false"/>
<apex:pageblocksectionitem />
</apex:pageblocksection>
<apex:pageblocksection title="System Information" showheader="true" columns="2">
<apex:pageblocksectionitem />
<apex:outputfield value="{!Service__c.RecordTypeId}"/>
</apex:pageblocksection>
</apex:pageblock>
</apex:form>
</apex:page>
Issue am facing:
When I choose the record type, other than "RFLEET_Option_OPP" It redirects to the Standard Page. Its working fine. But when I click the "RFLEET_Option_OPP" record type it redirects to the Vf page with below error
Visual force Error Cyclical server-side forwards detected: /apex/DemoVF?RecordTypeid=012580000000PIb