function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
mgodseymgodsey 

VF version of record type selection page

I've created a VF page to replace the standard record type selection page. It starts by clicking a custom "New" button with the following URL: /apex/NewMediaPlanOverride?oppid={!Opportunity.Id}

Here is the VF page:
<apex:page controller="NewMediaPlanOverride">
    <apex:form >
         <apex:pageMessages />
        <p style="font-size:20px"> What type of Media Plan are you creating?</p>
        <apex:commandButton action="{!newProposal}" value="Proposal"/>
        <apex:commandButton value="Insertion Order"/>
    </apex:form>

</apex:page>

The code works when I have it written this way:

public with sharing class NewMediaPlanOverride {
    public String oppId {get; set;}
   
    public NewMediaPlanOverride() {
        oppId = ApexPages.currentPage().getParameters().get('oppId');
    }
   
    public PageReference newProposal() {
        Savepoint sp = Database.setSavepoint();
       
        try{
            Quote newQuote = new Quote();
            Recordtype rt = [SELECT Name FROM RecordType WHERE Name = 'Proposal' and SObjectType = 'Quote' Limit 1];
            String recTypeId = rt.Id;
           
            //build the URL that the user will be redirected to
            //Quote is a standard object so the prefix is consistant across orgs
            String nextPage = '/0Q0/e?oppid=' + oppId + '&RecordType=' + recTypeId + '&retURL=%2F'+oppId + '&ent=Quote';
            PageReference pageRef = new PageReference(nextPage);  
            return pageRef;
               
        } catch(Exception e){
            Database.rollback(sp);
            ApexPages.addMessages(e);
            return null;
        }
}

However, since I'm going to have to repeat the redirect logic for different record types, I've tried to put it in its own method. Now when I click the button, it just stays on the same page instead of redirecting.

public with sharing class NewMediaPlanOverride {

    public String oppId {get; set;}

    public NewMediaPlanOverride() {
        oppId = ApexPages.currentPage().getParameters().get('oppId');
    }

    public void newProposal() {
        String recTypeId = getRecordTypeId('Proposal');
        newQuote(recTypeId);
    }

   public PageReference newQuote(String recTypeId){
       Savepoint sp = Database.setSavepoint();

       try{
            Quote newQuote = new Quote();
            //build the URL that the user will be redirected to
            //Quote is a standard object so the prefix is consistant across orgs

            String nextPage = '/0Q0/e?oppid=' + oppId + '&RecordType=' + recTypeId + '&retURL=%2F'+oppId + '&ent=Quote';
            PageReference pageRef = new PageReference(nextPage);  
            System.debug('[MF] nextPage: ' + nextPage);
            System.debug('[MF] pageRef' + pageRef);

            return pageRef;

       } catch(Exception e){

       System.debug('[MF] is there an error?' +e);
            Database.rollback(sp);
            ApexPages.addMessages(e);
            return null;
        }
    }

    public String getRecordTypeID(String type){
        RecordType rt = [SELECT Name FROM RecordType WHERE Name =:type AND SObjectType = 'Quote' Limit 1];
        String recTypeId = rt.Id;
        return recTypeId;
    }
}

Can anyone help me figure out why the second version of this code is not working? Here are the debug statements:
DEBUG|[MF] nextPage: /0Q0/e?oppid=006S00000070yVM&RecordType=012S00000004fibIAA&retURL=%2F006S00000070yVM&ent=Quote

DEBUG|[MF] pageRefSystem.PageReference[/0Q0/e?ent=Quote&oppid=006S00000070yVM&RecordType=012S00000004fibIAA&retURL=%2F006S00000070yVM]

Thank you!

Ramu_SFDCRamu_SFDC
Hi  the below post might give you some clue on the VF record type page redirect functinality

https://developer.salesforce.com/forums/ForumsMain?id=906F000000095W3IAI