How to set a date in apex test class?

284    Asked by Aalapprabhakaran in Salesforce , Asked on Sep 22, 2022

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';

You can do this using Date in Apex class:


      acc.effectiveDate__c = Date.newInstance(2016, 12, 9);

For more information check out the documentation: Apex Developer Guide - Date Class



Your Answer

Interviews

Parent Categories