
You need to construct a Date instance. Date someDate = Date.newInstance (2016, 4, 28); List<Date> dates = new List<Date> (); dates.add (someDate); Alternatively, you can construct a list with delineated elements if you use curly braces ({}) instead of parentheses (()).
Full Answer
How can I insert date through Apex code?
How can i insert date through Apex code? 1 Go to Setup 2 Open Developer Console 3 Select Debug 4 Open Anonymous Window 5 Execute following code and observe the result More ...
How do set methods work in Salesforce?
The Set methods work on a set, that is, an unordered collection of elements that was initialized using the set keyword. Set elements can be of any data type—primitive types, collections, sObjects, user-defined types, and built-in Apex types.
How do I set the effective date of a new account?
Account acc=new Account (); acc.effectiveDate__c= '09.12.2016'; For more information check out the documentation: Apex Developer Guide - Date Class Another option is using system.today () (or system.now () if it's datetime field):

How do I create a custom date in Apex?
Date format in ApexUse Date format method. String dateStr = Date. today(). format(); System. debug('>>>>' + dateStr); System. ... Convert to String directly. Date dToday = Date. today(); String dateStr = dToday. year() + '/' + dToday. month() + '/' + dToday. day(); ... Convert to DateTime.
How do I add dates to a list in Apex?
You need to construct a Date instance. Date someDate = Date. newInstance(2016, 4, 28); List
What is the format of date in Apex?
Usage. The specified string should use the standard date format “yyyy-MM-dd HH:mm:ss” in the local time zone.
How do I set time on Apex?
The following are methods for Time .addHours(additionalHours) Adds the specified number of hours to a Time.addMilliseconds(additionalMilliseconds) ... addMinutes(additionalMinutes) ... addSeconds(additionalSeconds) ... hour() ... millisecond() ... minute() ... newInstance(hour, minutes, seconds, milliseconds)More items...
How do I create a date field in Salesforce?
0:012:11[SALESFORCE] - How to Create a Date Field - YouTubeYouTubeStart of suggested clipEnd of suggested clipAnd under details is fields and relationships. Then click new. And then we'll scroll down click dateMoreAnd under details is fields and relationships. Then click new. And then we'll scroll down click date you can scroll up or down to click. Next.
How do you add days to a date field in Salesforce Apex?
use addDays & friends. Date d = getSomeDate();
How do I pass a date in Salesforce?
Salesforce: Passing DatesYYYY-MM-DD.YYYY-MM-DD hh:mm:ss.YYYY-MM-DDThh:mm:ssZ.YYYY-MM-DDThh:mm:ss. sssZ.
How do I convert datetime to date in Apex?
Convert Datetime to Date. DateTime dT = System.now(); Date d = Date.newInstance(dT.year(), dT.month(), dT.day());Convert Date to Datetime. Date d = Date.today(); Datetime dt = d; More from Salesforce notes. Follow. Toufik, Salesforce technical architect, based in Paris. May 4, 2020.
How do I format a date in a formula field?
Date format in Formula field and Apex in SalesforceTEXT(YEAR(DATEVALUE(Date__c) ))+ "/" +TEXT(MONTH(DATEVALUE(Date__c) ))+ "/" +TEXT(DAY(DATEVALUE(Date__c)))TEXT(MONTH(Date__c))+ "/" + TEXT(DAY(Date__c))+ "/" + TEXT(YEAR(Date__c))TEXT(DAY(Date__c))+ "/" +TEXT(MONTH(Date__c))+ "/" +TEXT(YEAR(Date__c))
How do I create an Apex code in Salesforce?
To write Apex code, you can choose from several Salesforce and third-party tools. Salesforce stores Apex classes as metadata. Apex code can be invoked by using triggers. Apex triggers can be configured to perform custom actions before or after changes to Salesforce records, such as insertions, updates, or deletions.
What is the common word for Apex '?
Some common synonyms of apex are acme, climax, culmination, peak, pinnacle, and summit. While all these words mean "the highest point attained or attainable," apex implies the point where all ascending lines converge.
What is true about the Apex programming language?
Apex is an object-oriented programming language present on the Salesforce platform. The language allows programmers to execute and perform transactions to control statements on servers associated with Salesforce. The language uses syntax that is extremely similar to that of Java.
daysBetween (secondDate)
Returns the number of days between the Date that called the method and the specified date.
daysInMonth (year, month)
Returns the number of days in the month for the specified year and month (1=Jan).
isSameDay (dateToCompare)
Returns true if the Date that called the method is the same as the specified date.
monthsBetween (secondDate)
Returns the number of months between the Date that called the method and the specified date, ignoring the difference in days.
newInstance (year, month, day)
Constructs a Date from Integer representations of the year, month (1=Jan), and day.
parse (stringDate)
Constructs a Date from a String. The format of the String depends on the local date format.
toStartOfWeek ()
Returns the start of the week for the Date that called the method, depending on the context user's locale.
addAll (fromList)
Adds all of the elements in the specified list to the set if they are not already present.
addAll (fromSet)
Adds all of the elements in the specified set to the set that calls the method if they are not already present.
containsAll (listToCompare)
Returns true if the set contains all of the elements in the specified list. The list must be of the same type as the set that calls the method.
containsAll (setToCompare)
Returns true if the set contains all of the elements in the specified set. The specified set must be of the same type as the original set that calls the method.
equals (set2)
Compares this set with the specified set and returns true if both sets are equal; otherwise, returns false.
removeAll (listOfElementsToRemove)
Removes the elements in the specified list from the set if they are present.
removeAll (setOfElementsToRemove)
Removes the elements in the specified set from the original set if they are present.
