-1

I tried insertion.It is working.Why UPDATION IS NOT WORKING?

   public static void updateTaskWithContact(list<string> getUpdatedRelatedContactList,string rId){
    SYSTEM.debug('getUpdatedRelatedContactList'+getUpdatedRelatedContactList);
    list<TaskRelation> updateRelation = new list<TaskRelation>();
    for(String obj:getUpdatedRelatedContactList){
        TaskRelation objTaskRelation = new TaskRelation(taskid=rId,iswhat=false);
        objTaskRelation.RelationId = obj;
        updateRelation.add(objTaskRelation);

    }
    //system.debug('updateRelation>>>>>'+updateRelation);
    UPDATE updateRelation;            
}

3 Answers 3

4

Update DML operation will not work in your case as I find that task records in the updateRelation list are not yet inserted (they don't have Id- they are not present in the database) so they can't be updated.

You need to perform either Insert or Upsert here.

As mentioned in the following documentation, update is not listed as a supported call : https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_taskrelation.htm

0

TaskRelation will not support UPDATE. TaskRelation will help you to INSERT DELETE AND UPSERT

-1

In line number 5 you have created new instance of TaskRelation and have added them to the list updateRelation.Since the records of TaskRelation in the list is not inserted yet,you can not perform Update(DML) operation.You should perform Insert in this scenario.

You must log in to answer this question.