I have written a test class in which I just want to set one date field. How can I achieve this? I am not able to set the value using the following code:
Account acc=new Account();
acc.effectiveDate__c= '09.12.2016';
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.
Sign up to join this communityYou can do this using Apex' Date class:
acc.effectiveDate__c = Date.newInstance(2016, 12, 9);
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):
acc.effectiveDate__c = System.today() + 5;
Another option is using system.today().addDays(10)
acc.effectiveDate__c = System.today().addDays(10);
a.SLAExpirationDate__c = date.parse('4/17/2020');
You need to use date.parse to execute the code