function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ian MacomberIan Macomber 

Updating a DateTime Field To Null

I'm trying to run an UPDATE statement in SOQL to set a DateTime field back to NULL (or whatever the default value is in Salesforce for DateTime fields) and running into issues with this.  Here are some of the statements I've tried to run with no success:

UPDATE CustomObject__c SET DateTimeField__c = NULL WHERE OtherField__c = 'value'
UPDATE CustomObject__c SET DateTimeField__c = null WHERE OtherField__c = 'value'
UPDATE CustomObject__c SET DateTimeField__c = '' WHERE OtherField__c = 'value'
UPDATE CustomObject__c SET DateTimeField__c = ' ' NULL WHERE OtherField__c = 'value'

Does anyone have any thoughts as to how this should work?
Best Answer chosen by Ian Macomber
Andrey VolosevichAndrey Volosevich
SOQL is not SQL, you cannot update records like this. You need to execute a DML update. Here are some examples in Apex you can have alook at: http://www.salesforce.com/us/developer/docs/apex_workbook/Content/apex6_5.htm

All Answers

Andrey VolosevichAndrey Volosevich
SOQL is not SQL, you cannot update records like this. You need to execute a DML update. Here are some examples in Apex you can have alook at: http://www.salesforce.com/us/developer/docs/apex_workbook/Content/apex6_5.htm
This was selected as the best answer
sandeep@Salesforcesandeep@Salesforce
Hi Ian, 

Firsly I would say that the way you have mentioned is not the way to update record in soql Here is the correct way below
Account a = new Account();
a = [select id,LaunchDatetime__c from Account where id ='00190000019VAShAAO'];
a.CSopke1__LaunchDatetime__c = NULL ;
update a ; 

Thanks
Sandeep Singhal
http://www.codespokes.com/