• snakecow2000
  • NEWBIE
  • 0 Points
  • Member since 2007

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
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
 
 
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