You need to sign in to do that
Don't have an account?
bsil bsil
System.ListException: Before Insert or Upsert list must not have two identically equal elements
I am getting the above error in the fllowing code how can i avoid this error..
Can any body suggest me how to fix this error
Apex Code:
list<Lead_Referral__c> conlist=new list<Lead_Referral__c>();
conlist = [select id, OwnerId,Contact_Name__c from Lead_Referral__c where id =: 'a06K0000009qFoT' or id =: 'a06K000000A4Yn9' or id =:'a06K0000009qG3s'];
Task LFUActivity = new Task();
list<Task> LFUActlist = new list<Task>();
for(integer j=0;j<conlist.size();j++){
LFUActivity.ownerId = conlist[j].OwnerId;
LFUActivity.ActivityDate = system.today();
LFUActivity.Priority = 'low';
LFUActivity.Status = 'Completed';
LFUActivity.Subject = 'JELD-WEN Lead Status Update Request Sent';
LFUActivity.Type = 'Automated Follow Up';
LFUActivity.WhatId = conlist[j].id;
LFUActivity.WhoId = conlist[j].Contact_Name__c;
LFUActivity.description = 'body1';
LFUActlist.add(LFUActivity);
}
insert LFUActlist;
Thanks In Advance..
Can any body suggest me how to fix this error
Apex Code:
list<Lead_Referral__c> conlist=new list<Lead_Referral__c>();
conlist = [select id, OwnerId,Contact_Name__c from Lead_Referral__c where id =: 'a06K0000009qFoT' or id =: 'a06K000000A4Yn9' or id =:'a06K0000009qG3s'];
Task LFUActivity = new Task();
list<Task> LFUActlist = new list<Task>();
for(integer j=0;j<conlist.size();j++){
LFUActivity.ownerId = conlist[j].OwnerId;
LFUActivity.ActivityDate = system.today();
LFUActivity.Priority = 'low';
LFUActivity.Status = 'Completed';
LFUActivity.Subject = 'JELD-WEN Lead Status Update Request Sent';
LFUActivity.Type = 'Automated Follow Up';
LFUActivity.WhatId = conlist[j].id;
LFUActivity.WhoId = conlist[j].Contact_Name__c;
LFUActivity.description = 'body1';
LFUActlist.add(LFUActivity);
}
insert LFUActlist;
Thanks In Advance..
LFUActivity.WhatId = conlist[j].id;
WhatId is different for all records..
Just try to initialization of LFUActivity into the for loop.
i.e
you got this error becasue in list the same record is inserted twise.
Regards
Virendra