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
PritikaPritika 

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!!




 
badibadi
Hi,

I have modified your code a little. Try this
 
public class CreateNewCompany_Extsn
 {
	public Account acc{get;set;}
    ApexPages.standardController m_sc = null;
    public Id 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()
     {
            Id selectedRecordType = ApexPages.currentPage().getParameters().get('RecordType');
			Id recTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Tender').getRecordTypeId();

            if(recTypeId == selectedRecordType){               
                PageReference ReturnPage = new PageReference('/apex/CreateNewCompany');           
               ReturnPage.setRedirect(true);
                return ReturnPage;
            }else{            
             	PageReference ret=new PageReference('/001/e?retURL=%2F001%2Fo&RecordType='+recTypeId +'&ent=Account');
    			ret.getParameters().put('nooverride','1');
    			return ret;
            }
         return null;
     }
 }

I have changed your recordtype comparsion from string to Id comparison
PritikaPritika
I changed the code as per your solution.But it always redirects to the vf page and does not redirect to standard page on other record type.I also tried without condition,yet it is navigating to the same vf page  CreateNewCompany everytime 
badibadi
Just to make sure . The New button for Account in Buttons, Links, and Actions is overriden with My Dummy VF Page right? 
PritikaPritika
Hi,I tried the above code with a samll URL change,It is working fine now..Thanks A lot!!