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
Dhananjaya BulugahamulleDhananjaya Bulugahamulle 

How to redirect to multiple VF pages according to record type ID?

User-added image
I figure it out when I click on the PB-005426 ({!p.Id}), to redirect to a new VF page layout (gibco2) with all vlues. But I have 5 different record type and VF pages. When user click on product brief number ({!p.Id}), I want to direct them to the right page. For Ex.

Record Type (RecordTypeId) = Media and Buffers then direct them to ('/apex/gibcopb2')
Record Type (RecordTypeId) = Hardware - S.U.B.then direct them to ('/apex/sum1')
Record Type (RecordTypeId) = BPC then direct them to ('/apex/page1')

In below code it only goes to one page('/apex/gibco2). I search for a example and could not find anything suitable for me. Most of them are confusing, and any idea how to assign multiple page according record type ID? Thanks.
<apex:page standardController="Product_Brief__c" extensions="DispatcherContactNewController">
</apex:pageBlock>
    </apex:form>
        <apex:pageBlock title="Recent Product Briefs">
            <apex:pageBlockTable value="{!pbs}" var="p" >
                <apex:column >
                    <apex:commandLink action="{! assetClicked}" value="{!P.Name}" id="theCommandLink"> 
                    <apex:param value="{!P.Id}" name="{!P.Id}" assignTo="{!selectedAsset}" ></apex:param>
                    </apex:commandLink>
                 </apex:column>
                 <apex:column value="{!p.RecordTypeId}"/>
            </apex:pageBlockTable> 
        </apex:pageBlock
    </apex:form>
</apex:pageBlock>

Extension
 
public class DispatcherContactNewController {

    public DispatcherContactNewController(ApexPages.StandardController controller) {
                this.controller = controller;
            }

    public ApexPages.StandardSetController setpb{
            get{
                if(setpb == null){
                    setpb = new ApexPages.StandardSetController(Database.getQueryLocator(
                        [SELECT Id, Name, RecordTypeId, Createddate FROM Product_Brief__c ORDER BY Createddate DESC ]));
                             setpb.setPageSize(10);
                             }
                             return setpb;
               } 
               set;
        }

        public List<Product_Brief__c>getpbs(){
            return (List<Product_Brief__c>)setpb.getrecords();
        }
/* ---------- For Redirect to New Page ------ */
 public string selectedAsset {get;set;}
    public PageReference assetClicked() 
    { 

    PageReference redirect = new PageReference('/apex/gibcopb2'); 

    // pass the selected asset ID to the new page
    redirect.getParameters().put('id',selectedAsset); 
    redirect.setRedirect(true); 

    return redirect;
    }
        }

 
Best Answer chosen by Dhananjaya Bulugahamulle
Amit Chaudhary 8Amit Chaudhary 8
Please try  below code . I hope that will help you.
public class DispatcherContactNewController {

    public DispatcherContactNewController(ApexPages.StandardController controller) {
                this.controller = controller;
            }

    public ApexPages.StandardSetController setpb{
            get{
                if(setpb == null){
                    setpb = new ApexPages.StandardSetController(Database.getQueryLocator(
                        [SELECT Id, Name, RecordTypeId, Createddate FROM Product_Brief__c ORDER BY Createddate DESC ]));
                             setpb.setPageSize(10);
                             }
                             return setpb;
               } 
               set;
        }

        public List<Product_Brief__c>getpbs(){
            return (List<Product_Brief__c>)setpb.getrecords();
        }
/* ---------- For Redirect to New Page ------ */
 public string selectedAsset {get;set;}
    public PageReference assetClicked() 
    { 
		PageReference redirect;
		if(selectedAsset != null )
		{
			List<Product_Brief__c> lstProd = [select id,name ,RecordType.Name from Product_Brief__c where id =:selectedAsset];
			if(lstProd.size() > 0 )
			{
				if(lstProd[0].RecordType.Name =='Media and Buffers')
				{
					 redirect = new PageReference('/apex/gibcopb2');
				}
				else if( lstProd[0].RecordType.Name =='Hardware - S.U.B.' )
				{
					 redirect = new PageReference('/apex/sum1'); 
				}
				else 
				{
					 redirect = new PageReference('/apex/page1'); 
				}
			}
		}
		
		// pass the selected asset ID to the new page
		redirect.getParameters().put('id',selectedAsset); 
		redirect.setRedirect(true); 
		return redirect;
    }
}
NOTE:- above code is not tested may be some syntex issue will come. Please let me know any issue will come

Please let us know if this will help you.

Thanks
Amit Chaudhary

All Answers

Amit Chaudhary 8Amit Chaudhary 8
Please try  below code . I hope that will help you.
public class DispatcherContactNewController {

    public DispatcherContactNewController(ApexPages.StandardController controller) {
                this.controller = controller;
            }

    public ApexPages.StandardSetController setpb{
            get{
                if(setpb == null){
                    setpb = new ApexPages.StandardSetController(Database.getQueryLocator(
                        [SELECT Id, Name, RecordTypeId, Createddate FROM Product_Brief__c ORDER BY Createddate DESC ]));
                             setpb.setPageSize(10);
                             }
                             return setpb;
               } 
               set;
        }

        public List<Product_Brief__c>getpbs(){
            return (List<Product_Brief__c>)setpb.getrecords();
        }
/* ---------- For Redirect to New Page ------ */
 public string selectedAsset {get;set;}
    public PageReference assetClicked() 
    { 
		PageReference redirect;
		if(selectedAsset != null )
		{
			List<Product_Brief__c> lstProd = [select id,name ,RecordType.Name from Product_Brief__c where id =:selectedAsset];
			if(lstProd.size() > 0 )
			{
				if(lstProd[0].RecordType.Name =='Media and Buffers')
				{
					 redirect = new PageReference('/apex/gibcopb2');
				}
				else if( lstProd[0].RecordType.Name =='Hardware - S.U.B.' )
				{
					 redirect = new PageReference('/apex/sum1'); 
				}
				else 
				{
					 redirect = new PageReference('/apex/page1'); 
				}
			}
		}
		
		// pass the selected asset ID to the new page
		redirect.getParameters().put('id',selectedAsset); 
		redirect.setRedirect(true); 
		return redirect;
    }
}
NOTE:- above code is not tested may be some syntex issue will come. Please let me know any issue will come

Please let us know if this will help you.

Thanks
Amit Chaudhary
This was selected as the best answer
Dhananjaya BulugahamulleDhananjaya Bulugahamulle
Hey Amit, Thank you very much for you help.