I have a use case where i have a list of orderItems which contains duplicates let us say:
OrderItem:{Product2__c=01t6F0000CCXXXXXX, Id=8026F00000EqzYYYYY},
OrderItem:{Product2__c=01t6F00000CCXXXXXX, Id=8026F00000Eqzba2AB},
OrderItem:{Product2__c=01t6F00000CCXXXXXX, Id=8026F00000Eqrbs3AB},
OrderItem:{Product2__c=01t6F000009kSSSSSS, Id=8026F00000Eqzx1RRR}
here first 3 orderitems are duplicate based on the field Product2__c so i want to make a seperate list of id's for duplicate records and unique records i have tried n implemented the below code but its not working as expected.
List<OrderItem> ListOI = new List<OrderItem>();<br/>
Set<String> DuplicateId = new Set<String>();<br/>
List<OrderItem> Item = [Select Id,Product2__c from Orderitem where OrderId =:OrderMap.keySet()];<br/>
for(OrderItem itemm : Item)
{
if(!DuplicateId.contains(itemm.Product2__c ))
{
ListOI.add(itemm);
DuplicateId.add(itemm.Id);
} else {
DuplicateId.add(itemm.Id);
}
}
can any one suggest me how to implement this in proper way