How to make a Date field null in Salesforce?

How to make a Date field null in Salesforce?

Use null value to make the Date field null.

Sample Code:

Account objAccount = [
    SELECT Id FROM Account WHERE Name = 'InfallibleTechie' LIMIT 1
];
Asset objAsset = new Asset(
    Name = 'Testing',
    AccountId = objAccount.Id,
    InstallDate = Date.today()
);
insert objAsset;
System.debug( 'Asset Install Date is ' + objAsset.InstallDate );
objAsset.InstallDate = null;
update objAsset;
objAsset = [ SELECT InstallDate FROM Asset WHERE Id =: objAsset.Id ];
System.debug( 'Asset Install Date is ' + objAsset.InstallDate );

Output:

Leave a Reply