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
snakecow2000snakecow2000 

Before Insert Trigger on Events

I am attempting to create a Before insert trigger which concatenates the Account name on the end of the Subject.  Here's my code:
/* Adds additional text to the entered Subject */
trigger triggerAddSubject on Event (before insert)
{
     Account subjectacct  = [select Id, Name from Account where Id = :Trigger.new.whoid];
     Trigger.new.subject = Trigger.new.subject + ' ' + subjectacct.name;
} // end of trigger
 
If I hard code an account guid into the query it works fine, apparently the whoid isn't set until the record is committed, so the subjectacct is null.
 
Have I just written it incorrectly or do I need to rewrite this as a after insert trigger?
 
Is there an easier way to do it?

Thanks,
 
Pat
 
 
snakecow2000snakecow2000
Solved my own problem, its WhatId not WhoId.  Just need to put some error handling in there.
iperez_geniusiperez_genius
maybe you are able to help me:
i ahve most of what i need i am jsut finding that the whatId is coming up with a null value
Code:
trigger updateLead on Task (before insert)
{
List<Lead> leadsToUpdate = new List<Lead>();
for (Task t: Trigger.new)
{
if (t.What.Type=='Lead' && t.Subject=='mailMerge')
{
Lead l = new Lead(Id = t.WhatId);
if (l.SentinfoPack__c == 'no')
{
l.SentinfoPack__c = 'yes';
leadsToUpdate.add(l);
}
}
}
update leadsToUpdate;
}

It seems like from printing out values for the red are both null and therefore the rest isn't processing.
the green is printing correctly