2

I am fetching dynamic field values in apex repeat so in these scenario, i am using 1 date field so when i fetch data then it show as a incorrect date format. How is this possible to show date in correct format.

VF Page:-

  <apex:repeat value="{!accessibleFieldsForObjectives}" var="fieldsForObjective" >
      <th>{!$ObjectType[objObjectiveName].fields[fieldsForObjective].Label}</th>
  </apex:repeat>
  <td> <apex:outputLabel value="{!$Label.PopupCommandLinkLabel}"/> </td>
</tr>
<apex:repeat value="{!allSchedules}" var="rec">  
  <tr>
    <apex:repeat value="{!accessibleFieldsForObjectives}" var="fieldsForObjective">
      <td>
         <apex:inputField value="{!rec.sObj[fieldsForObjective]}" style="width: 90px;"/> 
      </td>
</apex:repeat>
4
  • Are you referring to the selected date in your inputField? Feb 25, 2015 at 4:17
  • sorry for previous syntax as correct is:- Feb 25, 2015 at 4:29
  • <apex:repeat value="{!rec.children}" var="child"> <tr style="font-size: 11px;align-content: center;"> <apex:repeat value="{!accessibleFieldsForObjectives}" var="fieldsForObjective"> <td>{!child.sObj[fieldsForObjective]}</td> Feb 25, 2015 at 4:30
  • Kindly follow this as i am showing values using these syntex:- <td>{!child.sObj[fieldsForObjective]}</td> . Feb 25, 2015 at 4:31

2 Answers 2

1

You will need to identify the field type in your back-end and to create a map to keep the date fields. So your apex code should look something like this:

public Map <String, Boolean> fieldIsDate {get; set;}

private void populateListOfFields()
{
    fieldIsDate = new Map <String, Boolean> ();

    Map<String, Schema.SObjectField> M;
    M = Schema.SObjectType.Account.fields.getMap();
    for (String fieldName : M.keySet())
    {
        if (M.get(fieldName).getDescribe().getType().toString() == Schema.DisplayType.DATE)
        {
            fieldIsDate.put(fieldName, true);
            continue;
        }

        fieldIsDate.put(fieldName, false);
    }
}

Then in your visualforce page you'll know if the field name is of type date or not, and depending on that you can render the dates in a specific format:

<td>
    <apex:outputText value="{0, date, dd/MM/yyyy}" rendered="{!fieldIsDate[fieldsForObjective] == true}">
        <apex:param value="{!child.sObj[fieldsForObjective]}" name="p0" />
    </apex:outputText>
    <apex:outputField value="{!child.sObj[fieldsForObjective]}" rendered="{!fieldIsDate[fieldsForObjective] == false}" />
</td>
0

Your requirement don't seem to be clear. Firstly use outputfield if you want to display time. I assume that it can be datetime field so you have to convert it to date format.

Here is the pseudo code.

DateTime dT = System.now();
Date myDate = date.newinstance(dT.year(), dT.month(), dT.day());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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