Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am having trouble to add dates into the list. I tried the following.

//Create a list of medicine expiry dates
public class MedExpiry {
    List<Date> ExpDate = new List<Date>();
share|improve this question
up vote 7 down vote accepted

You need to construct a Date instance.

Date someDate = Date.newInstance(2016, 4, 28);
List<Date> dates = new List<Date>();

Alternatively, you can construct a list with delineated elements if you use curly braces ({}) instead of parentheses (()).

List<Date> dates = new List<Date> { someDate };
share|improve this answer
Thank you, it worked. – SF99 Mar 1 at 3:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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