I have following requirement,

Update Activity “Type” field with following:
Type = Call, if Subject starts with "Call" case-insensitive.
Type = Email, if Subject starts with "Email" case-insensitive.
Type = Task, for other Subject.
Type = Meeting, for all Events.

i have only one confusion that do i need to write 2 triggers for this like one for task and one for event

i have written trigger on task like

trigger updateTypeFieldOnTask on Task (before update,before insert) {
    List<task> taskList = new List<task>();
    for(task t: trigger.new) {
        if( t.Subject.startsWithIgnoreCase('Email')){
            t.type = 'Email';
        else if(t.Subject.startsWithIgnoreCase('Call')){
            t.type = 'Call';
        else if(t.Subject.startsWithIgnoreCase('Other')){
            t.type = 'Task';

it completes the 1st 3 requirement but for 4th requirement i.e
Type = Meeting, for all Events. do i need to write another trigger for event?


1 Answer 1


If you want to set fields on Event, you need a trigger on Event.

trigger Event on Event (before insert, before update)
    // implementation

However, all of the functionality you have been asked to build can be achieved via Workflow Rule Field Update, so you should go the declarative route here rather than adding code.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.