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
AngelikaAngelika 

How does Apex understand time?

Hi,

 

I am new to apex and am trying to build an apex schedule class that runs everyday. If the account review date for commisions is two weeks (14 days) away the scheduler will send an email to our Sales Department.

 

I have hit a wall....How does apex understand time? I need an email to be sent 2 weeks before the account review date but I'm not sure how to tel apex this.  I would want my code logic to run something like this...

 

if {!Account.Next_Account_Review_Date_c} == two weeks away OR

 

If today is two weeks before account review date

{

sends email

}

 

I don't have official code yet....but is my logic sound? How would I code in apex "two weeks/14 days away"?

 

Thanks for your help!

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Naidu PothiniNaidu Pothini
if (Account.Next_Account_Review_Date_c == System.Today().addDays(14))
{
    // code Send emails
}

 I guess this would help you.

 

-Naidu