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
BarryPlumBarryPlum 

Trigger doesn't seem to be working all the time

I wrote a trigger to fix the case where a task is created by automated systems with no Type.  We use type in analysis all the time, but not all integrations (including Mass Email within salesforce.com) will set the type.  Here is the original post.

So, here's the trigger, which works perfectly interactively:
Code:
trigger nullTaskType on Task (before insert,before update) {
  for (Task newTask : Trigger.new) {
   if (newTask.Type == null) {
    if (newTask.subject.startsWith('Email:') || 
     newTask.subject.startsWith('Brochure')||
     newTask.subject.startsWith('Mass Email') 
     ) {
    newTask.Type = 'Email';
  }
  if (newTask.subject.contains('Website Visit')) {
   newTask.Type = 'Website Visit';
  }
  if (newTask.subject.contains('Unsubscribed') || 
   newTask.subject.contains('Email click through') || 
   newTask.subject.contains('Email Viewed') || 
   newTask.subject.contains('Bounceback') || 
   newTask.subject.contains('Subscribed')
   ) {
    newTask.Type = 'Eloqua Response';
  }
   }
  }
}

 As you can see, it's very simple.  It works with my test code and works interactively, but there are still task sneaking in with no types.

I used one and prgramatically updated it (AJAX Tools rock) and the trigger fired as expected.

Any help would be appreciated.

jrotensteinjrotenstein
What is the subject of the Task that got through with a null type?

There's lots of 'else' cases in your code that could result in a null type.
BarryPlumBarryPlum
Yeah... I guess that would be helpful...

So, the one that stands out is Mass Email.  The others appear to be working.  I talked a bit with Developer support today on this and our suspicion is that, somehow, the activities created by Mass Email within salesforce are not allowing my trigger to fire.

If I go in and edit one, the trigger fires, or if I manually create one with the subject Mass Email it works.  But if I send a "Mass Email" to myself, the trigger doesn't seem to fire.

Obviously, you're right John, there are LOTS of subjects that would not fall into the statements, but I'm only concerned with the cases that should work.

:smileyhappy: