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
baltmannbaltmann 

How do you assign a date? Unexpected token 'birthdate'

trigger Contact1i on Contact (before insert) {

for( Contact c : Trigger.new )

{

if( c.birthdate = null)

{

c.birthdate = 1968-09-09;

}

update c;

}

}

Best Answer chosen by Admin (Salesforce Developers) 
crmexpertcrmexpert

in ur statement:

 

if( c.birthdate = null)

 

 

i sense that u are comparingtwo values, so in place of = you have to put ==

this mite be the reason that u r getting error..

 

 

regards,

All Answers

BritishBoyinDCBritishBoyinDC
It needs to be set to something defined as a date. Search in the apex docs for 'date methods' - you'll see examples of creating a new instance of a date, or converting a string to a date...
crmexpertcrmexpert

in ur statement:

 

if( c.birthdate = null)

 

 

i sense that u are comparingtwo values, so in place of = you have to put ==

this mite be the reason that u r getting error..

 

 

regards,

This was selected as the best answer
baltmannbaltmann
trigger Contact_i on Contact (before insert) {
for( Contact c : Trigger.new )
{
 
if( c.birthdate = null)
{
c.birthdate = date.ValueOf('1968-09-21');
}
update c;
}
}