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
Michael DsozaMichael Dsoza 

Access global class static variable directly on visualforce page like $User.CompanyName

Hi,
As having past java experience, we usually create separate file for CONSTANTS & their VALUES. Since we have "CUSTOM LABELS" in Salesforce to get String KEY & VALUE but we don't want these CONSTANTS to be change in future from SETUP. Also, Hard-Coding values are always bad practice and we have kept all this CONSTANTS in separate global class named "Global_Constants" where each constants is marked with static, final & assigned with value. 
Also, I had created getter method to access this static constant variable but whenever we try to access this, we receive error message as "variable_name does not exist". 
Can you please let us know, How can we create global page class like $User, $Label in Apex ?? OR
How can we access these CONSTANTS on VFPage without using these class as "Controller / Extensions" (Since I want to make it separate, global & to be accessible in every page)

Thanks.
karthikeyan perumalkarthikeyan perumal
Hello, 

Kindly Refer below, 

First of all you can't reference a variable from another class into your visualforce page. You can only reference variables from your controller.

If you're using a standard controller then you can do the following:

Utill Class which is used to get set variable only
public class Util {
    public static ID AccountId {
        get;
        set;
    }
}

And your VF page something like below, 
<apex:page standardController="Account" extensions="Util">
    <apex:outputText value="{!AccountId}" />
</apex:page>
Alternatively, if you're having a custom controller, you can make your Util class virtual or abstract and then extend it into your custom controller:
 
public with sharing class MyCustomController extends Util
{
    // your code
}

and your page will looke like:
 
<apex:page controller="MyCustomController">
    <apex:outputText value="{!AccountId}" />
</apex:page>

Hope this will help you, 
Mark Best ANSWER if its works for you. 

Thanks
karthik
Michael DsozaMichael Dsoza
Hi Karthik,

Thanks for your quick reply.
Do you have any idea about creating global page variables like $User, $Page etc. ??

​Thanks 
karthikeyan perumalkarthikeyan perumal
Hello, 

I am not sure we can create Custom global variable like user or page,  according to my understanding we can't create custom global variable. kinldy check the list of global variable avaliable in salesforce. 

http://http://help.skuid.com/m/11720/l/187263-global-merge-variables-functions

Hope this will help you 

Thanks
karthik
 
Shephali Swarnkar 9Shephali Swarnkar 9
Hi karthikeyan perumal,

        how to use  global class method string variable in another class??
for example :

  global class A{
              public class C
             {
                  public String id;
              }
           public static void B()
          {
           'id' is used here with some assignment
          }
}


here Iwant use 'id' in another class :
        I can use : A.B()            // to call static method but how to 'id' in this class


Awaiting your reply.
Thanks