5

For example we have $CurrentPage variable. How can I get all fields or methods which I can use for particular global variable? I don't see where they are stated like for URL class

Added. I understand that I can use some functionality in controller and then use variable from controller. I want to avoid using controller or extension. Don't try to solve a problem, just tell me where to get information. Thanks.

1
  • 1
    Please, can you leave a comment why you down voting? I understand upvote - people like this question and would love to have answer on this question too. Feb 6, 2014 at 12:57

1 Answer 1

5

Yes this is not very clearly documented the data types that reside behind the Visualforce Global Variables i totally agree. As such I can only give you the benefit of my experience in the past on figuring this out and few other examples in the documentation that support it.

Mapping Bindings to Methods

In respect to the $CurrentPage variable, this on first sight might appear to expose the instance methods PageReference data type, which was my first thought. However it's not always an exact science unfortunately. Typically once you establish the connection between the Apex system type (which is documented) and the global variable, you can remove the 'get' prefix from the methods and using them in your dot notation to access the information. Though in this case i don't think this is whats happening for $CurrentPage unfortunately, leaving us reliant on the examples in the docs and forums to derive.

$ObjectType Further Insight?

The classic one that has historically generated the most questions is $ObjectType, i now see that Salesforce has started to offer an explanation of the above and clarification of what it calls as a 'sub set' (mainly the getter methods) of the information exposed from the underlying Apex type (DescribeSObjectResult in this case).

Binding to Maps returned from Global Variable underlying Methods

Finally in respect to getter methods on underlying types, which return a Map, you can read up on how Visualforce generally handles these here. Which i thought would confirm the use of this syntax, {!$CurrentPage.parameters.relatedId} (since PageReference.getParameters() returns a Map). However looking at the docs around $ObjectType, the square bracket syntax is also valid, so i would have expected {!$CurrentPage.parameters['relatedId']} to also work, but it does not. Further confirming a lack of underlying relationship with PageReference.

Summary

It seems that in some cases if we know the underlying Apex system type we can use some rules and observations to find other information. This appears to be somewhat supported by the $ObjectType example, though my gut feel is $CurrentPage is bound to some internal type and not PageReference, since {!$Currentpage.anchor} yields an error on save.

Reading literally the paragraph of documentation for $CurrentPage, i can conclude that the only supported fields are $CurrentPage.Name, $CurrentPage.URL and $CurrentPage.parameteters, though as above, experimentation may yield others.

In short i would advise (via the doc feedback feature at the bottom of the docs) to encourage Salesforce to continue to expand out the information available on the Global Variables as they have done on $ObjectType quite well.

2
  • Indeed, some of variables have more or less full description. Thanks for your investigation. Feb 6, 2014 at 15:18
  • Your welcome, i like your motivation here as well, so often i see Apex controller methods just returning things the Global Variables could have provided, +1 for your question for best practice! :-) Feb 6, 2014 at 15:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .