Default Task Type to Email when sending an email

One question I hear over and over again, is why is the task type when I am sending an email in Salesforce not defaulted to Email? This is becomes an issue when you want to do reporting on all your tasks and they are logged as your default task type which generally is "Call".

I have written an Apex Trigger you can use to overwrite the Task Type and set it to "Email" when you are sending out an email from Salesforce. The trigger will look for "Email:" in the subject and also look for "Additional to:" as the first part of the description.

trigger SetTaskType on Task (before insert) { For (Task nc:Trigger.new) {   String subject = nc.Subject;   String description = nc.Description;

   if ( subject != null && subject.startsWith('Email:') && description.startsWith('Additional To:')) {    nc.Type = 'Email';   } }}
tagged Bookmark the permalink. Trackbacks are closed, but you can post a comment.
  • frasuy

    Would an email created from the Outlook plug-in resulting in an activity history record fire this trigger?

  • Kevin Josephson

    This is great — -I am able to get it to work in my sandbox. Can you share the apex class test code for this? While I can see the trigger working, I cannot get it to transfer over to production as my tests have not covered enough code. Thanks.

  • http://www.facebook.com/iknowyouthanyouknowme Kim Nino

    Thanks for your code.It answers my requirement.However,it seem doesn’t work when user’s language has been change from English.Could you give us another solution?