You need to sign in to do that
Don't have an account?
chaitanya salesforcecrm
Removing a List of values from set in apex?
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.
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
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
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.
All Answers
I have modified your code such that to achieve the same logic. try with below:
Let me know if you face any issues.
Thanks and Regards,
Sai Krishna Tavva.
It means that in case mainGroupLinkerIPGlist & toCopy lists have no common elements, then this function call will return false.
As a workaround, you can store size of IPGset before and after the function call and compare sizes to ascertain that values have been removed from IPGset.
Mark this as Best Answer, if this helps solve your problem.
Your query is adding the mainGroupLinkerIPGlist values again to toCopy List. i want to remove the mainGroupLinkerIPGlist values from toCopy List. for ex : if mainGroupLinkerIPGlist has {1,2} values and toCopy List has {1,2,3,4,5}. i want to remove {1,2} and keep only {3,4,5} in toCopy List.
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.
If you the answer the for this , please mark it as a best answer as it may helpful to others.
Thanks and Regards,
Sai Krishna Tavva.