You need to sign in to do that
Don't have an account?
Victor19
Open a Visualforce page for a specific record type
Hi All,
I am working on a requirement to open a visualforce page for a specific record type. For some reason, the page keeps going to the standard page layout. Could you please point out where I am going wrong. Please find my code below:
Visualforce Page:
<apex:page id="TestPage" standardcontroller="Test__c" tabStyle="Test__c" extensions = "TestController" action = "redirect">
</apex:page>
Controller:
public class TestController {
public ApexPages.StandardController controller{get;set;}
public TestController(ApexPages.StandardController controller) {
this.controller = controller;
}
public PageReference redirect() {
PageReference page = new PageReference('/apex/TestPage');
String selectedRecordType = ApexPages.currentPage().getParameters().get('RecordType');
if (selectedRecordType == '01XXXXXXXXX'){
page.setRedirect(true);
return page;
}
else{
return new PageReference('/a01/e?nooverride=1');
}
}
}
I would really appreciate if someone could suggest a fix to resolve this issue.
Thanks,
Victor
I am working on a requirement to open a visualforce page for a specific record type. For some reason, the page keeps going to the standard page layout. Could you please point out where I am going wrong. Please find my code below:
Visualforce Page:
<apex:page id="TestPage" standardcontroller="Test__c" tabStyle="Test__c" extensions = "TestController" action = "redirect">
</apex:page>
Controller:
public class TestController {
public ApexPages.StandardController controller{get;set;}
public TestController(ApexPages.StandardController controller) {
this.controller = controller;
}
public PageReference redirect() {
PageReference page = new PageReference('/apex/TestPage');
String selectedRecordType = ApexPages.currentPage().getParameters().get('RecordType');
if (selectedRecordType == '01XXXXXXXXX'){
page.setRedirect(true);
return page;
}
else{
return new PageReference('/a01/e?nooverride=1');
}
}
}
I would really appreciate if someone could suggest a fix to resolve this issue.
Thanks,
Victor
In below code you are sending to standard page layout if record Type is not equals to '01XXXXXXXXX'.
public PageReference redirect() {
PageReference page = new PageReference('/apex/TestPage');
String selectedRecordType = ApexPages.currentPage().getParameters().get('RecordType');
if (selectedRecordType == '01XXXXXXXXX'){
page.setRedirect(true);
return page;
}
else{
return new PageReference('/a01/e?nooverride=1');
}
}
If Every time you want to redirect to VF page then please try below code
public PageReference redirect() {
PageReference page = new PageReference('/apex/TestPage');
String selectedRecordType = ApexPages.currentPage().getParameters().get('RecordType');
page.setRedirect(true);
return page;
}
Please let us know if this will help you.
Thanks
Amit Chaudhary
Thanks for the tip... It is still taking me to the standard page layout.
Basically when the record type = '01XXXXXXXXX'. It has to take me to the Visualforce Page. Otherwise (for other record types) it has to go to the standard page layout.
You have any suggestions
Thanks,
Victor
Please let us know is this will help you.
The code works for this record type. Basically what I did was I overwrote my New Button with this VF Page.
The issue I am having now is for the other record types that have different standard page layouts.. it keeps getting redirected to the default page layout.. As in the record types when selected does not go to the page layout assigned to them.
Could you please suggest a fix?
I appreciate the help.