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
Pierre OlivierPierre Olivier 

Method does not exist or incorrect signature: NOW()

Hi community, I am new in Apex language, I am trying to create a simple trigger to update a contact field but when I try to put a condition with the method NOW() or TODAY() it returns this error : Method does not exist or incorrect signature: NOW(). Do you know why? Here is my code :

 

trigger UpdtConAct on Event (after insert, after update) {
   
// create a set for related contact ids
 Set<ID> contactids = new Set<ID>();
 
// iterate through the events
    for ( Event status : trigger.new){
    // add the event only if the surgery appened less than 30 days ago
        if (status.Subject == 'Surgery'){
         if (    (Status.ActivityDate.daysbetween(NOW())) < 30 )
        {contactids.add(status.WhoId);}

                                                              }

                                                         }
        
// use SOQL to query for the relevant contact
        List <Contact> contactlist = [SELECT id ,Surgeon_Status__c from Contact where id in : contactids];
 // iterate through the contacts
        for (Contact con : contactlist){
            con.Surgeon_Status__c='Active';}
        update contactlist;
    }

 

Thanks for your answer.

 

Pierre

Saikishore Reddy AengareddySaikishore Reddy Aengareddy

if (    (Status.ActivityDate.daysbetween(Date.Today())) < 30 )

Pierre OlivierPierre Olivier
Thank you very much it works fine now.

Pierre