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
podgercor1.3917890117104897E12podgercor1.3917890117104897E12 

event trigger problem

I'm trying to write a trigger that will fire when an event is marked as Completed (on custom Status field). When this happens I want to update the related Account with a timestamp of when this happened
i.e Event marked completed - Account field Timestamp is set to today

i've tried writing the code for it but have not been able to get beyond the below, any ideas/tips would be appreciated - thanks

code -------------------------

trigger Timestamper on Event (after insert, after update)
{
  List <ID> AccId = New List <ID>();
   
    for (Event e: trigger.new)
    {
     if (e.Meeting_Status__c == 'Completed' && e.WhatId !=null)
         {
          AccId.add(e.WhatId);  
         }
    }

   
    List <Account> accList = [SELECT id, Timestamp__c FROM Account WHERE id in:AccId];
    {
     accList.Timestamp__c = System.today();  
    }
    update accList;
}

i think i am close here but getting an "initial term of field expression must be a concrete SObject" error here??
Best Answer chosen by podgercor1.3917890117104897E12
SaiGSaiG
Try the code below ...

trigger Timestamper on Event (after insert, after update)
{
  List <ID> AccId = New List <ID>();
  
    for (Event e: trigger.new)
    {
     if (e.Meeting_Status__c == 'Completed' && e.WhatId !=null)
         {
          AccId.add(e.WhatId); 
         }
    }

  
    List <Account> accList = [SELECT id, Timestamp__c FROM Account WHERE id in:AccId];
    for(Account acnt : accList)
    {
         acnt.Timestamp__c = System.today(); 
    }
    update accList;
}

All Answers

SaiGSaiG
Try the code below ...

trigger Timestamper on Event (after insert, after update)
{
  List <ID> AccId = New List <ID>();
  
    for (Event e: trigger.new)
    {
     if (e.Meeting_Status__c == 'Completed' && e.WhatId !=null)
         {
          AccId.add(e.WhatId); 
         }
    }

  
    List <Account> accList = [SELECT id, Timestamp__c FROM Account WHERE id in:AccId];
    for(Account acnt : accList)
    {
         acnt.Timestamp__c = System.today(); 
    }
    update accList;
}
This was selected as the best answer
podgercor1.3917890117104897E12podgercor1.3917890117104897E12
Thank you SaiG, that worked a treat
SaiGSaiG
Great. Can you please mark this as answered.

Thanks,
Sai