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
SoCal AdminSoCal Admin 

Accessing class variables


I developed a Chart from a custom salesforce object, but I'm trying in vain to assign a value to a public class variable.


I'm trying to add String data from a LIST<>[Select] output (which works correctly) to a class variable so the TITLE of the chart in the Visualforce page can access it, but I can't seem to SET the value to the public variable.


Obtaining the actual value from the List<>[Select] is easy and works (as tested in Execute Anonymous query}.  SETTING the value appears impossible.  Is there a special notation when assigning values to variables that are defined by "{ get;set;}?



I have the following:


public class zchartController {

        public String RecentDate { get ; set; }   //  This is where the Controller added the reference.

        //  I also tried putting the LIST<>[Select] here.


public static List<Data> getChartData() {

        List<MyObj__c> CurrentDates = [Select OrderDate__C from MyObj__c order by OrderDate__c Limit 1];
        //    RecentDate = CurrentDates.get(0).OrderDate__c;








Best Answer chosen by Admin (Salesforce Developers) 
SoCal AdminSoCal Admin


Nevermind.  I figured it out.


I was trying to assign the value in a different subclass.  All I had to do was create a simple class constructor that assigned the value.