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
dwright-glgroupdwright-glgroup 

Creating a shared activity from Apex example

Does anyone have an example you're willing to share of creating a task from Apex code and attaching multiple contacts?

 

Vinit_KumarVinit_Kumar

Hi,

 

Try below :-

 

conList= [select id from Contact limit 9];

User u =[select id from User where name='<some user in ur org>'];

for(Contact c:conList){
for(integer i=0;i<=conlist.size();i++){
Task t = new Task(Status='Not Started',Priority='Normal',OwnerId=u.id,WhoId=c.id);
insert t;
}
}

 

dwright-glgroupdwright-glgroup

Hi Vinit,

 

   That code will create a non-shared task, but what I want to do is to have multiple contacts for the task, e.g.

 

Id contactIdOfJoe;    // primary contact

Id contactIdOfFred;  // secondary contact

 

   new Task(Status=,, WhoId=contactIdOfJoe,   .... (something) = contactIdOfFred);

 

Thanks,

Dave