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
Patrick DixonPatrick Dixon 

Custom controller - how to return a record based on current page name

Hi

 

I want to return a custom object  record based on a query using the name of the VF page.  I can do it using an id with :ApexPages.currentPage().getParameters().get('id') ... but that's not what I want.

 

Please can someone fill in the ?????s below for me?

 

public with sharing class PageRenderer {

    public Page_Layout__c[] getPageLayout() {
         return [select Name,
             nav_level_1__c,
             nav_level_2__c,
             page_title__c
            
             from Page_Layout__c
             where name = ??????];
     }
}

Ritesh AswaneyRitesh Aswaney

return [select Name,
             nav_level_1__c,
             nav_level_2__c,
             page_title__c
            
             from Page_Layout__c
             where name = :Page.PAGENAME];

where pagename is the name of ur vf page ?

Patrick DixonPatrick Dixon

Thanks - but I want it to give the controller the name of the current VF page, so that I can use the controller across all pages.  Otherwise I'd have to hard code the name in to each page's controller.

 

Where is all the Page.  Site. variable stuff documented? A couple of hours googling has failed to find anything useful.

Patrick DixonPatrick Dixon

I could pass it as a variable from the VF page to the controller (using $CurrentPage.Name) but I haven't figured out how to do that either.