0

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:

enter image description here

Clone:

enter image description here

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.

2
  • For record type, you will need to build your own selection picklist field using <apex:selectOption>. For the Save and New button, you can use the same code you have for save(), you just need to redirect back to this page. Commented Nov 20, 2018 at 4:54
  • @DavidCheng thanks David, I had that idea in my mind (the one from the save and new), but wanted to know if there was a standard method to achieve that also, but nevermind, I did as you suggested and it works. For the record type issue, I think is not what I'm looking for, I need to show the selected RecordType in the previous page and show it there.
    – AjFmO
    Commented Nov 20, 2018 at 14:57

1 Answer 1

0

Found the solution for this.

Apex code in constructor:

 public String recordTypeId { get; set; }

    public CreateCommLogController() {
        recordTypeId = ApexPages.currentPage().getParameters().get('RecordType');
        List<RecordType> rtIds = [SELECT Name from RecordType where Id = :recordTypeId LIMIT 1];
        if (rtIds.size() > 0) {
            recordTypeName = rtIds[0].Name;
        }
    }

Code in Visualforce Page:

<apex:pageBlockSectionItem >
    <apex:outputLabel value="Record Type"/>
    <apex:outputText value="{!recordTypeName}"/>
</apex:pageBlockSectionItem>

Done

enter image description here

You must log in to answer this question.

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