i have crate a multiple assignment task for same opportunity with different users. i have write this code for task creation
public PageReference saveTask(){
if(IdTask.size()>0){
List<Task> taskList = new List<Task>();
for(String str : IdTask){
newTask.OwnerId=str;
taskList.add(newTask);
}
try{
insert taskList;
}catch(DMLException e){
}
PageReference parentPage = new PageReference('/' + WhatId);
parentPage.setRedirect(true);
return parentPage;
}
return null;
}
but getting a error. but owner id different.
System.ListException: Before Insert or Upsert list must not have two identically equal elements
Visualforce:
<apex:PageBlockSection title="Task Information">
<apex:pageBlockSectionItem >
<apex:outputLabel >Assigned To</apex:outputLabel>
<apex:outputLabel style="border-left-color: #c00;">
<apex:outputLabel >{!assignedToLable}<br/></apex:outputLabel>
<apex:outputLabel style="font-weight:bold;">{!assignedToTaskSize}</apex:outputLabel>
</apex:outputLabel>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel >Related To</apex:outputLabel>
<apex:inputField value="{!newTask.WhatId}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel >Subject</apex:outputLabel>
<apex:inputField value="{!newTask.Subject}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel >Name</apex:outputLabel>
<apex:inputField value="{!newTask.WhoId}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel >Type</apex:outputLabel>
<apex:inputField value="{!newTask.Type}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel >Due Date</apex:outputLabel>
<apex:inputField value="{!newTask.ActivityDate}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel >Comments</apex:outputLabel>
<apex:inputField value="{!newTask.Description}" />
</apex:pageBlockSectionItem>
</apex:PageBlockSection>
pls help me out.