0

I am getting an error like duplicate iD. Wrapperlist is a List of contact

    id taskId = '00T****005ezShPEAU';
    list<task> updateTask = new list<task>();
    Type idArrType = Type.forName('List<string>');
    List<string> wrapperList = (List<string>) JSON.deserialize(getSelectedContact, idArrType);
    for(string lst :wrapperList){
        Task taskObj = new Task(id=taskId);
        updateTask.add(new Task(
            whoid =lst,
            id=taskObj.id
        ));
    }
    update updateTask;

How can I resolve this error?

  • 2
    You cannot set multiole WhoId, Try to set something like this: if (wrapperList.size() > 0) {getTask.WhoId = wrapperList[0];} – Mariia Illarionova Jan 29 at 9:26
  • @MariiaIllarionova I need set list of who id to a particular task ID – user75427 Jan 29 at 9:33
  • 1
    Yes you cannot set list to single Id, may be you need to create separate task for each whoid. – Sunil Aware Jan 29 at 10:20
  • can you please elaborate your question a little more.if your wrapperlist is contains list of contacts then storing it in list<String> will cause problem while accessing contacts other attribute. – Ranjit Mishra Jan 29 at 11:51
  • @ranjitMishra It is not causing problem. I need to assign multiple contacts to a single task. – user75427 Jan 29 at 12:10
0

To associate multiple Contacts to one Task, your Salesforce org must have Shared Activities turned on. This will allow you to link up to 50 Contacts to a single Task. Without this feature active, you may associated only one Contact to a Task.

With Shared Activities, WhoId remains a single field - you can't assign a list to it unless you're using the SOAP API. To associate multiple Contacts to the Task, you'd need to write code to create TaskRelation objects, where the RelationId field is the Contact's Id, and the TaskId field is the Task's Id.

| improve this answer | |

Your Answer

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