How to set a Date in apex test class?

1.1K    Asked by bruce_8968 in Salesforce , Asked on Jul 19, 2021

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


Answered by Celina Lagunas

You can do this using Apex' Date class:

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


Your Answer

Interviews

Parent Categories