Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save charltonAthletic/6ae5a6f8085e72b6e23b to your computer and use it in GitHub Desktop.
Save charltonAthletic/6ae5a6f8085e72b6e23b to your computer and use it in GitHub Desktop.
// This simple trigger changes the value of the standard Activity field 'Type' on task records to 'Email' if, before insert, the task is BLANK.
// This trigger could be improved upon by creating a method in a helper class to keep the trigger logicless.
trigger TaskWithBlankType of Task (before insert) { // 'before insert' is the trigger context variable
for (Task t : Trigger.new) { // for loop - for all tasks which match the trigger context variable...
if (t.Type == null) { // if branch nested in the for loop. If the type on the task is empty...
t.Type = 'Email'; // change the value of the Type to 'Email'. Remember: no DML operations required on 'before' trigger context variables
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment