You need to sign in to do that
Don't have an account?
BManojKumar
How to redirect the page to visual force page based on the record type selection
Hi All,
I have a set of record types for opportunities in my organization. I have a visual force page. I would like to redirect the user to the visual force page whenever a particular record type is selected in the drop down list.
Can anyone help me out , how to do this ?
Thank in Advance.
Good Day.
In VF page add action attribute in apex:page tag
In the extensions class create a method Redirect containing the logic
This should do it!!
Let me know if any issues
All Answers
Hi,
You can use the recordtype ID to redirect.
Just override the New button with your VF page & add the redirection logic in that page. To redirct to standard SFDC page you can add the override parameter in URL
In VF page add action attribute in apex:page tag
In the extensions class create a method Redirect containing the logic
This should do it!!
Let me know if any issues
This is similar to the previous posters answer without needing a controller.
The record type that has been selected is being passed to whatever page is used for the New function with the record type id being passed in a "RecordType" parameter on the URL.
Let's assume that the ID of the RecordType for the Opportunity for which you want to use your own VF page is '012A0000000RFok'.
So, you create a VF page called "MyNewOpportunity" and use it as the override for the New operation on Opportunities.
Which is essentially saying, if the RecordType parameter we've been passed is NOT the one for which you want to use this VF page, then redirect to a URL which is built for the New Opportunity action (/006/e), however don't override the default New action with your VF page (true), and pass along the RecordType that the user selected in the first place (RecordType=$CurrentPage.parameters.RecordType)
Best. Steve.
Hi SteveBower / sinsiterrulez , Thanks for your help.. Its fix my issue..
Have a nice day..
I actually found a way to redirect user to the specific Visual Force page based on profile attached record type. I have achived this using Custom Settings Object. Created Custom Setting Object as list with hirarchy and visabulity public. and Created Record Type, PageName fields. and used the below code to redirect user based on the record type.
Controller
******************************************************************************************************************************
public with sharing class OpportunityCSController{
public CreateOpportunity__c recordtypemapping ;
public Set<String> recordtypenames = new Set<String>();
public OpportunityCSController(ApexPages.StandardController controller) {
recordtypemapping = CreateOpportunity__c.getInstance(UserInfo.getProfileId());
System.debug(recordtypemapping);
}
String recType;
public List<SelectOption> getrectypes() {
System.debug(recordtypemapping);
String[] recordtypes = new List<String>();
recordtypes = recordtypemapping.recordtype__c.split(',',recordtypemapping.recordtype__c.length());
if(recordtypes.size()==0){
recordtypes.add(recordtypemapping.recordtype__c);
}
recordtypenames.addAll(recordtypes);
List<SelectOption> options = new List<SelectOption>();
for(RecordType rt:[select id,name from RecordType where sobjecttype = 'CRM_Opportunity__c' and DeveloperName IN: recordtypenames]){
options.add(new SelectOption(rt.name,rt.name));
}
return options;
}
public String getRecordType() {
return recType;
}
public void setRecordType(String recType) {
this.recType= recType;
}
public PageReference save()
{
string idr;
string st ='';
system.debug('sttype'+st);
idr=ApexPages.currentPage().getParameters().get('Contactid');
string qrystring = [SELECT PageName__c FROM CreateOpportunity__c WHERE RecordType__c =:st][0].PageName__c;
PageReference home = new PageReference(qrystring+idr);
home.setRedirect(true);
return home;
}
public PageReference cancel()
{
string idr;
idr=ApexPages.currentPage().getParameters().get('Contactid');
PageReference home = new PageReference('/'+idr);
home.setRedirect(true);
return home;
}
public string rtps {get; set;}
}
********************************************************************************************************************
Visual Force Page
<apex:page standardController="CreateOpportunity__c" extensions="OpportunityCSController" action="{!save}">
<apex:sectionHeader subtitle="New Opportunity"/>
<apex:form ><apex:pageBlock title="{!$ObjectType.CRM_Opportunity__c.label} New" mode="new">
<apex:pageBlockButtons >
<apex:commandButton action="{!Save}" value="Next"/>
<apex:commandButton action="{!cancel}" value="Cancel"/>
</apex:pageBlockButtons>
<apex:pageBlockSection showHeader="true" title="Select Record Type" columns="2">
<apex:selectList value="{!RecordType}" multiselect="false" size="1">
<apex:selectOptions value="{!rectypes}"/>
<apex:actionSupport event="onchange" rerender="bb" status="status"/>
</apex:selectList>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>