Accessing any visualforce page with one force.com site

Now a days we are focusing on force.com sites to attract public visitors and gather data with less cost. Though force.com guest profile is accessible out of SF licenses, it still has limitations with number of sites to be created. That will cause problems when we need to navigate to the certain page.
I just found an easy way to access any page with having a parameter in the url. We will see with an example and demo.
Code:
VF:
<apex:page showHeader="false" sidebar="false" controller="pkHomeController" standardStylesheets="false">
    
<html>
<body>

    <apex:outputPanel rendered="{!isAvailable}">
      <apex:include pageName="{!pId}" />
    </apex:outputPanel>   
    

</body>
</html>
</apex:page>
Controller:
public class pkHomeController {

    public Boolean isAvailable { get; set; }
    public String pId {get; set;}
    
    
    public pkHomeController(){
        isAvailable = true ;
        pId = 'boot';
        String pName = ApexPages.currentPage().getParameters().get('id') ;
        if(string.isNotBlank(pName)){
            
            ApexPage ap = [SELECT Id, Name FROM ApexPage WHERE Name=:ApexPages.currentPage().getParameters().get('id') LIMIT 1];
            if(ap <> null)
                pId = ap.Name;
        }else{
            isAvailable = false ;
        }
       
    }
    
    
}
So when we pass “id” parameter as VF page name in the url and if it is having enough accesses from guest profile then this page can be accessible in force.com site.
Same way we can frame links and access any VF page built in the org.
Hope this helps in some way. Cheers!

Comments