1

I have a Date field that I want to track the history of into a long text field, but I can't figure out how to get the correct date format (4/25/2015).

For example: for my Date field, if it equals 4/25/2015 and changes to 4/27/2015.

I want my Long text field to = 4/25/2015; 4/27/2015 and so on. How can I write this in a trigger or class?

I current have:

if (Trigger.isUpdate && new.Datefield != old.Datefield)
{
   new.longtextfield = new.datefield + ';' + old.longtextfield;
}

Which does not work. Could someone help me out?

4
  • Salesforce stores dates in GMT, which can sometimes be a problem. Do you need this to be in a particular time zone? Mar 25, 2015 at 21:39
  • Why not just use field history tracking?
    – Adrian Larson
    Mar 25, 2015 at 21:58
  • Not necessarily, I'm not too worried about the time. I just need the date. If I need a time zone then I can use Central (Chicago). Mar 25, 2015 at 21:58
  • @AdrianLarson this date field changes often, so tracking the field could get messy. Mar 25, 2015 at 21:59

1 Answer 1

2

Salesforce date fields can be manipulated by the DateTime class. Try using one of the "format" methods provided to convert the date field into a string, in your local timezone and desired format, and then you can concatenated the dates.

You must log in to answer this question.

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