I have an object as objDates with field names as Day1__c, Day2__c and so on till Day366__c. I'm using DayOfYear() to access the field values dynamically. I'm able to read(get) and write (put) values dynamically through anonymous apex. However, I'm not able to get a list or map to display on a Visual force page to display the column names as dates. I'm trying to get the visual force page display a month at a time like this: 1/1/2018 | 1/2/2018 and so on and accept values for the corresponding fields (Day1__c,Day2__c...) to the dates displayed. I tried maps, list and so on. How can I get it working?

  • 4
    Please include a specific example of what you have tried and where you are stuck. – Adrian Larson May 13 '18 at 18:01
  • I'm not sure where to start, I've tried many ways. The last I tried was Keith C's suggestion. I created another controller for the dates as columns without binding to any object. for (Integer i = 0; i < 31; i++) { Date dRunningDate = dFirstDayOfMonthCurrentMonth.addDays(i); columns.add(String.valueOf(dRunningDate)); } Then I'm trying to bind it to the object and map the dates with the field names. – Donald Reagan May 13 '18 at 20:34
  • This seems to me to be an X-Y problem. Having an object with 366 fields (one for each day) is a pretty big red flag for me. It would probably help if you described the problem, the "X", that you're attempting to solve with your current approach , the "Y" (i.e. having on object with 366 fields and trying to build a visualforce page using individual days), instead of how to make your current approach work. – Derek F May 14 '18 at 13:02

Breaking the fields up into month groups and columns (?) is probably best done by you using a custom class instance per month.

On the dynamic presentation of fields in Visualforce it's:

<apex:repeat value="{!fields}" var="field">
    <apex:inputField value="{!objDates[field]}"/>

assuming a controller that includes:

public ObjDates__c objDates {get; set;}
public String[] fields {
    get {
        if (fields == null) {
            fields = new String[] {};
            for (Integer i = 1; i <= 366; i++) fields.add('Day' + i + '__c');
        return fields;
  • Thanks! I think that's exactly what I want, I'm getting the right input fields, however, I want to be able to display the dates as column names above the input fields like this: 1/1/2018 | 1/2/2018... – Donald Reagan May 13 '18 at 19:40
  • Hi Keith C, Any solutions/ideas to this? Thanks for your help – Donald Reagan May 14 '18 at 20:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.