2

I need to display "Not Available" on a date field. Actual_Delivery_Date__c and calculated_actual_delivery_date__c are date fields. So the following code works fine

        tempOrderLines[i].calculated_actual_delivery_date__c=tempShipmentLines[i].Actual_Delivery_Date__c;

But I want to calculated_actual_delivery_date__c to have the text value Not Available. I don't want to change the field type from DATE. I don't know if its possible I tried the following:

  1. tempOrderLines[i].calculated_actual_delivery_date__c="Not Available";
  2. tempOrderLines[i].calculated_actual_delivery_date__c=date.valueof("Not Available");
  3. tempOrderLines[i].calculated_actual_delivery_date__c='Not Available';

Is there any way/trick to add string to date?

Thanks.

2
  • 1
    Can you clarify why a field that has non-Date information needs to stay a Date type? Would it be just as good if it were a Text field that contained a MM/DD/YYYY formatted date? Sep 14, 2014 at 17:13
  • Yes certainly. calculated_actual_delivery_date__c is a date type formula field. There is a requirement that if field is blank, then it should be display "Not Available". It that possible?
    – MnZ
    Sep 14, 2014 at 17:40

1 Answer 1

4

If you want to change the display of the field in a Visualforce page then you could:

  • Wrap the parent sObject in another object and use a custom property to display either the field value or 'Not Available'
  • Use visualforce markup to toggle between two different controls with the rendered attribute. One would show the date value, the other the static text 'Not Available'.

A third option would be to create a formula field that shows the required value.

5
  • I'm more inclined to the 3rd option. But I will have to comment out many vf pages to change the field type. I will try the 2nd option too. Thnx :-)
    – MnZ
    Sep 14, 2014 at 19:45
  • It's probably easier to just create a new formula field than to change the field type on the field you have. Sep 15, 2014 at 11:26
  • I tried, but then found out that I have to go back to my model and change. Can I use javascript to fill in the required text if I find that table cell empty.
    – MnZ
    Sep 16, 2014 at 6:53
  • @MnZ You certainly could put some Javascript to a Visualforce page to make changes as required. Is there a reason a formula field wouldn't work for you? Sep 16, 2014 at 10:29
  • Yes. For ex. my field is Estimated Delivery Date. If I use formula field, its going to be a formula(text). So if I have to assign this field to another DATE field, say Calculated Date, which is a date field, I get the field type error; says it has to be correct type. I hope you got my point!
    – MnZ
    Sep 16, 2014 at 10:33

You must log in to answer this question.

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