I had to override the New button to use a clone of the record page of a Custom Object, so far so good, now I need to be able to catch the record type selected like in the original page.
Original:
Clone:
Also, I would like to add the Save & New button.
Code:
Controller:
public with sharing class CreateCommLogController {
public ApexPages.StandardController stdCtrl;
public Communication_Log__c communicationLog { get; set; }
public Id communicationLogId { get; set; }
public CreateCommLogController() {
}
public CreateCommLogController(ApexPages.StandardController controller) {
this.stdCtrl = controller;
communicationLog = (Communication_Log__c) controller.getRecord();
communicationLogId = communicationLog.Id;
}
public PageReference save() {
String recordType = ApexPages.currentPage().getParameters().get('RecordType');
insert communicationLog;
PageReference pr = new PageReference('/apex/VFP_RelatedMultipleRecords?newid=' + Communication_Log__c.Id + '&recordOrigin=' + Communication_Log__c.Id + '&master=' + Communication_Log__c.Master_Communication_Log__c);
pr.setRedirect(true);
pr.getParameters().put('RecordType', recordType);
return pr;
}
}
VFP:
<apex:page standardController="Communication_Log__c" extensions="CreateCommLogController" docType="html-5.0">
<apex:sectionHeader subtitle="New Communication Log" title="Communication Log Edit"/>
<apex:form >
<apex:pageBlock title="Communication Log Edit">
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Save"/>
<!--<apex:commandButton action="{!saveandnew}" value="Save & New"/>-->
<apex:commandButton action="{!cancel}" value="cancel"/>
</apex:pageBlockButtons>
<apex:pageBlockSection collapsible="false" columns="2">
<apex:outputField value="{!Communication_Log__c.RecordType.Name}"/>
<apex:inputField value="{!Communication_Log__c.Organization_Name__c}" id="commAccount"/>
<apex:inputField required="true" value="{!Communication_Log__c.Event_Subject__c}" id="eventSubject"/>
<apex:inputField value="{!Communication_Log__c.Contact_Name__c}" id="contact"/>
<apex:inputField required="true" value="{!Communication_Log__c.Brief_Desscription__c}" id="title" style="width: 255px !important;"/>
<apex:inputField value="{!Communication_Log__c.Activity_Name__c}" id="activity"/>
<apex:inputField type="datetime" required="true"
value="{!Communication_Log__c.Event_Start_date_time__c}"
id="startDate"/>
<apex:inputField value="{!Communication_Log__c.Project_Name__c}" id="project"/>
<apex:inputField type="datetime" required="true" value="{!Communication_Log__c.Event_End_date_time__c}"
id="endDate"/>
<apex:inputField value="{!Communication_Log__c.Related_Communication_Log__c}" id="relatedLog"/>
<apex:inputField value="{!Communication_Log__c.Meeting_Type__c}" id="meetingType"/>
</apex:pageBlockSection>
<apex:pageBlockSection title="Additional Information" collapsible="false" columns="1">
<apex:inputField value="{!Communication_Log__c.Event_Description__c}" style="width: 255px !important;"/>
<apex:inputField value="{!Communication_Log__c.SCE_s_Main_Contact_for_this_Event__c}" style="width: 255px !important;"/>
<apex:inputField value="{!Communication_Log__c.Location__c}" style="width: 255px !important;"/>
<apex:inputField value="{!Communication_Log__c.Agenda_Link__c}"/>
<apex:inputField value="{!Communication_Log__c.Level_of_Engagement__c}"/>
<apex:inputField value="{!Communication_Log__c.No_of_Tickets_available_for_this_event__c}" style="width: 255px !important;"/>
<apex:inputField value="{!Communication_Log__c.Contributions_Type__c}"/>
<apex:inputField value="{!Communication_Log__c.Requested_Amount__c}"/>
<apex:inputField value="{!Communication_Log__c.SCE_Officers_Role__c}" style="width: 255px !important;"/>
<apex:inputField value="{!Communication_Log__c.SCE_Personnel_Attendees__c}" style="width: 255px !important;"/>
<apex:inputField value="{!Communication_Log__c.Key_Stakeholders_Attendees__c}" style="width: 255px !important;"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Thanks in advance.
<apex:selectOption>
. For the Save and New button, you can use the same code you have forsave()
, you just need to redirect back to this page.