You need to sign in to do that
Don't have an account?
sfuser12
System.ListException: Duplicate Id in List Error
Hello,
I am getting error duplicate Id. Can anyone suggest what to do?
Set<Id> leadIds = new Map<Id, Lead>([SELECT Id, OwnerId
FROM Lead]).keySet();
List<Lead> leads = [SELECT Id, OwnerId
FROM Lead
Where LeadSource =: LeadSourceSelection
and Owner.Name =:LEAD_QUALIFICATION_QUEUE_NAME
and Id=:leadIds
];
List<Lead> leadsToUpdate=new List<Lead>();
for( UserWrapper agentUserWrapper : agentWrappers ) {
System.debug('CFRRetentionSiteDashboardController2.assignLeads - agent ' + agentUserWrapper.agent );
System.debug('CFRRetentionSiteDashboardController2.assignLeads - agentUserWrapper ' + agentUserWrapper.numberOfLeadsToAssign );
// System.debug('CFRRetentionSiteDashboardController2.assignLeads - ListOfLead - ' + ListOfLead );
for(Lead lead :leads) {
System.debug('CFRRetentionSiteDashboardController2.assignLeads - lead--' +lead);
lead.OwnerId = agentUserWrapper.agent.Id;
lead.Retention_Owner__c = agentUserWrapper.agent.Name;
if(currentSite != null) {
lead.Retention_Site__c = currentSite.Id;
leadsToUpdate.add(lead);
}
}
}
update leadsToUpdate;
System.debug('CFRRetentionSiteDashboardController2.assignLeads-- leadsToUpdate'+leadsToUpdate);
I am getting error duplicate Id. Can anyone suggest what to do?
Set<Id> leadIds = new Map<Id, Lead>([SELECT Id, OwnerId
FROM Lead]).keySet();
List<Lead> leads = [SELECT Id, OwnerId
FROM Lead
Where LeadSource =: LeadSourceSelection
and Owner.Name =:LEAD_QUALIFICATION_QUEUE_NAME
and Id=:leadIds
];
List<Lead> leadsToUpdate=new List<Lead>();
for( UserWrapper agentUserWrapper : agentWrappers ) {
System.debug('CFRRetentionSiteDashboardController2.assignLeads - agent ' + agentUserWrapper.agent );
System.debug('CFRRetentionSiteDashboardController2.assignLeads - agentUserWrapper ' + agentUserWrapper.numberOfLeadsToAssign );
// System.debug('CFRRetentionSiteDashboardController2.assignLeads - ListOfLead - ' + ListOfLead );
for(Lead lead :leads) {
System.debug('CFRRetentionSiteDashboardController2.assignLeads - lead--' +lead);
lead.OwnerId = agentUserWrapper.agent.Id;
lead.Retention_Owner__c = agentUserWrapper.agent.Name;
if(currentSite != null) {
lead.Retention_Site__c = currentSite.Id;
leadsToUpdate.add(lead);
}
}
}
update leadsToUpdate;
System.debug('CFRRetentionSiteDashboardController2.assignLeads-- leadsToUpdate'+leadsToUpdate);
Ravi Dutt Sharma
Why do you have a for loop inside another for loop. For the first iteration of agentWrappers list, it will add all the lelads to leadsToUpdate list. Then for the next iteration, it will again add the same leads to leadsToUpdate list.
Raj Vakati
Try this code