0

I have a scenario. A simple one but not able to understand the language of it.

We need to update the Activity(Task\Event) field Type value with Meeting for all the Event.

What could be the code like.

For(Task t:trigger.new) {

t. Type='Meeting';

}

My issue is how to relate all Events with this code???

  • 1
    Is this one time operation? Do you want to run an operation to change all Events to set Meeting as their Type? Or do you want to set this value as a default for all new Events? – Carlos Naranjo Jan 6 at 13:04
  • Actually the requirement is like Activity object , Type field shud be meeting for all the Events. I think it is for existing. So I don't know the right approach. – vineet Jan 6 at 13:44
  • 1
    "Activity" isn't a real object; it's kind of like an abstract base class. The concrete sObjects are Task and Event. – David Reed Jan 6 at 13:46
  • Yeah I think, I got an answer. I was just confused with the Activity object. As you told its an abstract base class. So, now I have to focus either on Task or Event. @David Reed – vineet Jan 6 at 13:56
0

This is too much for comments, so I'm going to write it as an answer. First, there's an object called Event which is different than Task. Both are considered an Activity. So, please be clear on whether you are trying to update the Event or the Task object. This could be done by either a trigger or a Process Builder.

What will be important to know is what Tasks or "Events" you want to update the Type to "Meeting" on. What was the previous value for Type? Obviously, you don't want to update the value on all Tasks, only those that meet a certain criteria. Is it based on the Subject, the AccountId, the WhoId, WhatId, or something else? See the ObjectReference for Task for available fields on Task.

Let's assume your Tasks were created without specifying the Type. To catch those and update them to change the blank value (a picklist) to "Meeting", you'd do something like what's below:

Using a very basic trigger, your code would look something like this:

trigger MyTrigger on Task (after Insert) {
    list<Task>toUpdate = new list<Task>();
    for(Task t: trigger.new){
        if(isEmpty(t.Type)){
            t.type = 'Meeting';
            toUpdate.add(t);
        }
    }
    update toUpdate;
}
  • Yeah I got the answer. The same logic can be written for Event object also. Earlier I thought that any one of them will do the job, so I was trying to relate Event with Task. Now, I think the same logic, I can write for Event object Type field. – vineet Jan 6 at 13:58

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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