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
sml9099sml9099 

hard code date field in apex trigger

Hi All , 

I have wriiten a very simple trigger which will update the field value based on the start date. This startd date is custom date field (start_date__c). The trigger is below. I want to hard code the date field value in IF condition, I cannot hard code that field or i dont know how to hard code date field.Can you please help me ?

trigger convertedamountGBP on Schedules_and_Actuals__c (before insert,before update) {

        for ( Schedules_and_Actuals__c sch : trigger.new)
            {
          
               if (sch.Start_Date__c  = '2014-01-01')
                   {
                   sch.Converted_Amount_GBP__c = sch.Converted_currency_USD__c*2 ;
                   }
                  
             }

}
Best Answer chosen by sml9099
GlynAGlynA
Sorry - need '==' : 

if ( sch.Start_Date__c == Date.newInstance( 2014, 1, 1 ) )

-Glyn

All Answers

GlynAGlynA
Use:

if ( sch.Start_Date__c = Date.newInstance( 2014, 1, 1 ) )

Glyn Anderson
Sr Developer | System Analyst | ClosedWon | closedwon.com
Certified Developer | Certified Advanced Administrator
Twitter: @GlynAtClosedWon
GlynAGlynA
Sorry - need '==' : 

if ( sch.Start_Date__c == Date.newInstance( 2014, 1, 1 ) )

-Glyn
This was selected as the best answer
sml9099sml9099
awesome...Thanks Glyn