0

I have a requirement where I want to put type=='meeting' for all the events type has a picklist data type where meeting is a value

Here is the trigger I have written but it is not working.

trigger FieldUpdaterofEvent on Event (before insert,before update) {
    list<event> toUpdate = new list <event>();
    for(Event eve:trigger.new){
        if(eve.type=='--None--'){
            eve.type='Meeting';
            toUpdate.add(eve);
        }
    }
    update toUpdate;
}
2

As per my understanding, you want all event records whose Type is not set, to be created with Type as Meeting.

This can be done by setting the default value to Meeting on the Type picklist field.

If you still want to do it by trigger, then this is how your trigger should be

trigger FieldUpdaterofEvent on Event (before insert,before update) {
    for(Event eve:trigger.new){
        if(string.isBlank(eve.type)){
            eve.type='Meeting';
        }
    }
}
  • As you are writing the trigger for before insert and before update event, all the records won't be committed to database yet, hence you don't have to write explicit DML statements for it.
  • When comparing the picklist value, you will have to check it against '' or null (You can use String.isBlank or String.isEmpty) and not --None--, unless you have --None-- as a picklist value which I doubt.
4
  • line list<event> toUpdate = new list <event>(); is superfluous
    – cropredy
    May 31 '19 at 13:18
  • Thanks @cropredy, corrected it May 31 '19 at 13:25
  • thanks a lot and could please help me with this also Activity Score on Contact and Account should be updated based on following formula. Contact/Account Activity Score = Count of Meetings * 3 + Count of calls * 2 + Count of Emails * 1 Note: This count will be done for all child activities May 31 '19 at 18:20
  • what should i do with it May 31 '19 at 18:21

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.