function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Andrey HarutyunyanAndrey Harutyunyan 

How to set whatId through Apex for already existed Events and Tasks?

List<Event> EventsList = [SELECT Id FROM Event WHERE WhoId = :contactId];
for(Event E : EventsList){
    // the line below gives an error about invalid method. what code should I write?
    // E.setWhatId(accountId);
}
I need to set whatId of events and tasks of a contact who just was been converted from a lead to a contact skipping opportunity creation. But couldn't find according info to do that.

Thanks,
Andrey
Best Answer chosen by Andrey Harutyunyan
Agustin BAgustin B
HI Andrey, what about this?
List<Event> EventsList = [SELECT Id,whatid FROM Event WHERE WhoId = :contactId];
for(Event E : EventsList){
    // the line below gives an error about invalid method. what code should I write?
    E.whatid=accountId;
}
update EventsList;


If it helps please mark as correct, it may help others.

All Answers

Agustin BAgustin B
HI Andrey, what about this?
List<Event> EventsList = [SELECT Id,whatid FROM Event WHERE WhoId = :contactId];
for(Event E : EventsList){
    // the line below gives an error about invalid method. what code should I write?
    E.whatid=accountId;
}
update EventsList;


If it helps please mark as correct, it may help others.
This was selected as the best answer
Andrey HarutyunyanAndrey Harutyunyan
Hi Agustin,

thanks a lot for your quick reply and help. It worked.