Skip to main content
I have two lists(mainGroupLinkerIPGlist and toCopy) i am trying to remove all the values of mainGroupLinkerIPGlist from toCopy by creating a set and adding both the lists to the IPGset. below is the apex code.

 

List<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());

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: false
5 answers
  1. Jun 13, 2016, 7:52 AM
    Hi Chaitanya,

    try below code. 

    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);

    }

    }

    }

    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.
0/9000