Play Games

Search This Blog

Friday, August 31, 2018

Error: Compile Error: Illegal assignment from Datetime to Date

This error generally arise when you are assigning datetime field value to Date.
Example :
Assume submitted_Date__c is a date field created on Account.

Account acc = new Account();
DateTime dt = system.Now();
acc.submitted_Date__c = dt;// This line gives error as dt is a datetime field assigning to Date field(submitted_Date__c)

Solution:Convert DateTime to Date and then assign it to other date field.

use date() to convert DateTime to date.
Account acc = new Account();
DateTime dt = system.Now();
acc.submitted_Date__c = dt.date();

No comments:

Post a Comment