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
LaurenP6777LaurenP6777 

Direct to Visualforce Page after Record Type Selection

I would like to direct users to a visualforce page that clones the opportunity AFTER they choose a record type. 

 

Is there a way that I can rewrite the button code to somehow "detour" to the opportunity record type selection page prior to going to the vf page? 

 

/apex/addstudyED?id={!Opportunity.Id}

 

OR  

 

Can i somehow add code to the controller that will allow the user to stop at the record type selection page?

 

 

 

public class AddSTudyEDController {

//added an instance varaible for the standard controller
private ApexPages.StandardController controller {get; set;}
// add the instance for the variables being passed by id on the url
private Opportunity o {get;set;}
// set the id of the record that is created -- ONLY USED BY THE TEST CLASS
public ID newRecordId {get;set;}

// initialize the controller
public AddStudyEDController(ApexPages.StandardController controller) {

//initialize the stanrdard controller
this.controller = controller;
// load the current record
o = (Opportunity)controller.getRecord();

}

// method called from the VF's action attribute to clone the po
public PageReference AddStudyED() {

// setup the save point for rollback
Savepoint sp = Database.setSavepoint();
Opportunity newO;


try {

//copy the purchase order - ONLY INCLUDE THE FIELDS YOU WANT TO CLONE
o = [select Id, RFI__c,Molecule_Size__c, Name,AccountId, Parent_Opportunity__r.Record_Type_Name__c,Parent_Opportunity__c,Compound_Name__c, Compound__r.Id, StageName, Currency_To_Quote__c,CloseDate, Program_Managed__c,Integrated_Opportunity2__c,funding_approved__c from Opportunity where id = :o.id];
newO = o.clone(false);

if(o.Parent_Opportunity__c==null)
newo.Parent_Opportunity__c = o.Id;

if(o.Parent_Opportunity__r.Record_Type_Name__c=='ED - ADMIN TEST'
||o.Parent_Opportunity__r.Record_Type_Name__c=='BIOA'
||o.Parent_Opportunity__r.Record_Type_Name__c=='TOX'
||o.Parent_Opportunity__r.Record_Type_Name__c=='BIOTECH'
||o.Parent_Opportunity__r.Record_Type_Name__c=='DM'
||o.Parent_Opportunity__r.Record_Type_Name__c=='CMC')
newo.Parent_Opportunity__c = o.Parent_Opportunity__c;

if(o.Parent_Opportunity__r.Record_Type_Name__c!='ED - ADMIN TEST'
&&o.Parent_Opportunity__r.Record_Type_Name__c!='BIOA'
&&o.Parent_Opportunity__r.Record_Type_Name__c!='TOX'
&&o.Parent_Opportunity__r.Record_Type_Name__c!='BIOTECH'
&&o.Parent_Opportunity__r.Record_Type_Name__c!='DM'
&&o.Parent_Opportunity__r.Record_Type_Name__c!='CMC')
newo.Parent_Opportunity__c = o.id;


newo.Name = 'pending - must overwrite';
newo.Stagename = 'Prospect';


insert newO;

// set the id of the new po created for testing
newRecordId = newO.id;

// copy over the line items - ONLY INCLUDE THE FIELDS YOU WANT TO CLONE
List<OpportunityContactRole> items = new List<OpportunityContactRole>();
for (OpportunityContactRole cr : [Select r.Id, r.ContactId, r.OpportunityId, r.IsPrimary, r.role From OpportunityContactRole r where OpportunityId = :o.id]) {
OpportunityContactRole newcr = cr.clone(false);
newcr.OpportunityId = newO.id;
items.add(newcr);
}


// copy over the line items - ONLY INCLUDE THE FIELDS YOU WANT TO CLONE
List<OpportunityTeamMember> teams = new List<OpportunityTeamMember>();
for (OpportunityTeamMember tm : [Select m.Id, m.OpportunityAccessLevel, m.OpportunityId, m.UserId, m.IsDeleted, m.TeamMemberRole From OpportunityTeamMember m where OpportunityId = :o.id]) {
OpportunityTeamMember newtm = tm.clone(false);
newtm.OpportunityId = newO.id;
teams.add(newtm);
}
insert items;
insert teams;

} catch (Exception e){
// roll everything back in case of error
Database.rollback(sp);
ApexPages.addMessages(e);
return null;
}

return new PageReference('/'+newO.id+'/e?retURL='+O.id+'&saveURL='+newO.id);
}

}

 

 

 

Rahul_sgRahul_sg

There is a setting Skip Record Type Selection Page available when you overwrite a button using a VF page.

LaurenP6777LaurenP6777

That is an interesting feature that I was not aware of but it seems to only be available when you overwrite the standard "new" button. My button is simple custom button that deep clones certain related lists on an opportunity. Everything works perfect except I need to stop at the Opportunity Record Type selection page before moving to the VF page.

 

Thanks!

 

Rahul_sgRahul_sg

oki then do 1 thing. 

Add a PAgeblock section/Page block for whatever code you have and add another pageblocksection/page block (a new section)

 

In that new section use selectlist /selectoption tag to display recortype selection. Make this section visible when the User hits button and after selecting a Recordtype (add next button or use JS function) hide this section.

and display the section you have already created.