You need to sign in to do that
Don't have an account?
Pritika
how to display different vf pages and standard page on the selection of record type
My requirement is if record type A is selected then VF page of account A should be selected ,if record type b is selected then standard account page should be displayed.I don't want the vf page to be displayed at all for other record types.I tried using the action function on the same Page,then it was going in infinite loop.I used action function on a dummy page redirecting to the main page,I wanted to check recordtype selected and on the basis of that it should redirect to vf page or standard page.However somehow it is not able to select the record type and always goes in the Else part,irrespective of what record type I select.
hereis the code snippet:
My Dummy VF Page:
<apex:page standardController="Account" extensions="CreateNewCompany_Extsn" action="{!redirectCompany}" >
</apex:page>
My main VF Page:
<apex:page standardController="Account" extensions="CreateNewCompany_Extsn" id="Page" tabstyle="Account" >
<!---- Script ----->
<script>
some logic
</script>
<!---- /Script ----->
<apex:form id="form">
<apex:actionFunction ..>
<apex:pageBlock title="Company Edit">
<apex:pageBlockSection title="abc" >
....
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton action="{!cancel}" value="Cancel"/>
<apex:commandButton value="Save" id="saveAction" onclick="return myJavascriptFunc();"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller Extension:
public class CreateNewCompany_Extsn
{
public Account acc{get;set;}
ApexPages.standardController m_sc = null;
public string type{get;set;}
public CreateNewCompany_Extsn(ApexPages.standardController sc)
{
m_sc = sc;
acc = new account();
acc.OwnerId = UserInfo.getUserId();
type = apexpages.currentpage().getParameters().get('RecordType');
}
public PageReference RedirectSalesAreaCompany()
{
Account acc = (Account)m_sc.getRecord();
insert acc;
Pagereference redirectTo=new Pagereference('/apex/CreateSalesAreaData?AccId='+acc.Id+'&type=new');
return redirectTo;
}
public PageReference redirectCompany()
{
String selectedRecordType = ApexPages.currentPage().getParameters().get('RecordType');
Id recTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Tender').getRecordTypeId();
if(String.valueOf(recTypeId) == selectedRecordType){
PageReference ReturnPage = new PageReference('/apex/CreateNewCompany');
ReturnPage.setRedirect(true);
return ReturnPage;
}else{
return null;
}
}
}
So in this example,even if I select Tender Record type,it still returns null.So I guess it is not able to fetch the record type.
Please Help!!
hereis the code snippet:
My Dummy VF Page:
<apex:page standardController="Account" extensions="CreateNewCompany_Extsn" action="{!redirectCompany}" >
</apex:page>
My main VF Page:
<apex:page standardController="Account" extensions="CreateNewCompany_Extsn" id="Page" tabstyle="Account" >
<!---- Script ----->
<script>
some logic
</script>
<!---- /Script ----->
<apex:form id="form">
<apex:actionFunction ..>
<apex:pageBlock title="Company Edit">
<apex:pageBlockSection title="abc" >
....
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton action="{!cancel}" value="Cancel"/>
<apex:commandButton value="Save" id="saveAction" onclick="return myJavascriptFunc();"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller Extension:
public class CreateNewCompany_Extsn
{
public Account acc{get;set;}
ApexPages.standardController m_sc = null;
public string type{get;set;}
public CreateNewCompany_Extsn(ApexPages.standardController sc)
{
m_sc = sc;
acc = new account();
acc.OwnerId = UserInfo.getUserId();
type = apexpages.currentpage().getParameters().get('RecordType');
}
public PageReference RedirectSalesAreaCompany()
{
Account acc = (Account)m_sc.getRecord();
insert acc;
Pagereference redirectTo=new Pagereference('/apex/CreateSalesAreaData?AccId='+acc.Id+'&type=new');
return redirectTo;
}
public PageReference redirectCompany()
{
String selectedRecordType = ApexPages.currentPage().getParameters().get('RecordType');
Id recTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Tender').getRecordTypeId();
if(String.valueOf(recTypeId) == selectedRecordType){
PageReference ReturnPage = new PageReference('/apex/CreateNewCompany');
ReturnPage.setRedirect(true);
return ReturnPage;
}else{
return null;
}
}
}
So in this example,even if I select Tender Record type,it still returns null.So I guess it is not able to fetch the record type.
Please Help!!
I have modified your code a little. Try this
I have changed your recordtype comparsion from string to Id comparison