You need to sign in to do that
Don't have an account?
SFDC Guest
Display visualforce based on record type selected
Hi All,
I am trying to display vf pages based on record type selected from standard salesforce page. I have two record types API Names are - RecordType1, RecordType2. Customer__c is object api name. After selecting record type and clicking on next button, i am getting below error.
Visualforce Error
Help for this Page
System.NullPointerException: Attempt to de-reference a null object
Error is in expression '{!redirectToNewVFPage}' in component <apex:page> in page recordtypepage: Class.NewCustomerExtension.redirectToNewVFPage: line 13, column 1
Class.NewCustomerExtension.redirectToNewVFPage: line 13, column 1
Below is the code.
public with sharing class NewCustomerExtension {
public String recordTypeId;
public NewCustomerExtension (ApexPages.StandardController std) {
}
public Pagereference redirectToNewVFPage(){
Pagereference pg = null;
if(ApexPages.CurrentPage().getParameters().get('RecordType') != null){
recordTypeId = ApexPages.CurrentPage().getParameters().get('RecordType');
if(recordTypeId == Schema.SObjectType.Customer__c.getRecordTypeInfosByName().get('RecordType1').getRecordTypeId()){
// pg = new Pagereference('/apex/Page1');
pg = Page.Page1;
}else if(recordTypeId == Schema.SObjectType.Customer__c.getRecordTypeInfosByName().get('RecordType2').getRecordTypeId()){
// pg = new Pagereference('/apex/Page2'); // Add Parameters to Page if Needed
pg= Page.Page2;
}
pg.setRedirect(true);
return pg;
}
return null;
}
}
Page Name: RecordTypePage
<apex:page standardController="Customer__c" extensions="NewCustomerExtension" action="{!redirectToNewVFPage}">
</apex:page>
PageName: Page1:
<apex:page standardController="Customer__c" >
Page 1
</apex:page>
PageName: page2
<apex:page standardController="Customer__c" >
<h1>Congratulations</h1>
This is your new Page
</apex:page>
I have overrided New button with page: RecordTypePage.
Plz let me know how to redirect to their respective pages. Thanks in advance.
I am trying to display vf pages based on record type selected from standard salesforce page. I have two record types API Names are - RecordType1, RecordType2. Customer__c is object api name. After selecting record type and clicking on next button, i am getting below error.
Visualforce Error
Help for this Page
System.NullPointerException: Attempt to de-reference a null object
Error is in expression '{!redirectToNewVFPage}' in component <apex:page> in page recordtypepage: Class.NewCustomerExtension.redirectToNewVFPage: line 13, column 1
Class.NewCustomerExtension.redirectToNewVFPage: line 13, column 1
Below is the code.
public with sharing class NewCustomerExtension {
public String recordTypeId;
public NewCustomerExtension (ApexPages.StandardController std) {
}
public Pagereference redirectToNewVFPage(){
Pagereference pg = null;
if(ApexPages.CurrentPage().getParameters().get('RecordType') != null){
recordTypeId = ApexPages.CurrentPage().getParameters().get('RecordType');
if(recordTypeId == Schema.SObjectType.Customer__c.getRecordTypeInfosByName().get('RecordType1').getRecordTypeId()){
// pg = new Pagereference('/apex/Page1');
pg = Page.Page1;
}else if(recordTypeId == Schema.SObjectType.Customer__c.getRecordTypeInfosByName().get('RecordType2').getRecordTypeId()){
// pg = new Pagereference('/apex/Page2'); // Add Parameters to Page if Needed
pg= Page.Page2;
}
pg.setRedirect(true);
return pg;
}
return null;
}
}
Page Name: RecordTypePage
<apex:page standardController="Customer__c" extensions="NewCustomerExtension" action="{!redirectToNewVFPage}">
</apex:page>
PageName: Page1:
<apex:page standardController="Customer__c" >
Page 1
</apex:page>
PageName: page2
<apex:page standardController="Customer__c" >
<h1>Congratulations</h1>
This is your new Page
</apex:page>
I have overrided New button with page: RecordTypePage.
Plz let me know how to redirect to their respective pages. Thanks in advance.
and based on what you are stating
will return null and thus getRecordTypeId() will throw the null pointer exception.
getRecordTypeInfosByName needs the name of the recordtype as a parameter and not the api name.
All Answers
and based on what you are stating
will return null and thus getRecordTypeId() will throw the null pointer exception.
getRecordTypeInfosByName needs the name of the recordtype as a parameter and not the api name.