when i am trying to remove all the mainGroupLinkerIPGlist values from set it is not removing and i am getting below message. System.AssertException: Assertion Failed: Expected: true, Actual: falseList<Intralinks_Group_and_Contact_Links__c> mainGroupLinkerIPGlist = [SELECT Id,Intralinks_Portal_Group__c FROM Intralinks_Group_and_Contact_Links__c where Contact__c = :mainGroupLinker.Contact__c];
//system.debug('mainGroupLinkerIPGlist =' + mainGroupLinkerIPGlist.size());
//query all the Groups the copyFrom contact has
if(copyFrom.Contact__c != null) {
List<Intralinks_Group_and_Contact_Links__c> toCopy = [SELECT Id,Intralinks_Portal_Group__c FROM Intralinks_Group_and_Contact_Links__c where Contact__c = :copyFrom.Contact__c];
system.debug('toCopy =' + toCopy.size());
set<Intralinks_Group_and_Contact_Links__c> IPGset = New set<Intralinks_Group_and_Contact_Links__c>(toCopy);
boolean result = IPGset.removeall(mainGroupLinkerIPGlist);
System.assertEquals(true, result);
system.debug('mainGroupLinkerIPGlist Count=' + mainGroupLinkerIPGlist.size());
system.debug('IPGset count=' + IPGset.size());
Hi Chaitanya, try below code.
Let me know if you have any queiries. Also mark it as best answer if it solves your questions.Thanks and Regards,Sai Krishna Tavva.list<Integer> toCopy = new list<Integer>{1,2,3,4,5};
list<Integer> mainGroupLinkerIPGlist = new list<Integer>{1,2};
for(Integer i: mainGroupLinkerIPGlist ){
for(integer k = 0; k<toCopy .size()-1; k++){
if(i == toCopy [k] ){
toCopy .remove(k);
}
}
}