You need to sign in to do that
Don't have an account?
Shrey Tyagi
Combine 2 lists to make a set - Please help!!!
Hi Everyone,
Due to some SOQL sub query limitations I have to query list of opportunity records into 2 seperate lists. for our e.g lets call them List A and List B.
So List A gets its values from soql query
List<Opportunity> ListA=[select Id, Name from Opportunity where StageName='Claosed Won'];
List<Opportunity> ListB=[select Id,Name from Oppoortunity where Sub_Stage__c='Aawarded'];
Set<Opportunity> SetC=ListA+ListB.
Now I want to combine List A and List B , take out the duplaicate data out of the combination and make a set out of it Set c= List A+ List B ( but it should not have any duplaicate records)
Can anyone please help me with the syntax to join 2 lists into a set?
Please note that due to some limits I cannot get all my data into 1 list . The where clause e/g used above are just for theory . It's bit more complicated than that.
Due to some SOQL sub query limitations I have to query list of opportunity records into 2 seperate lists. for our e.g lets call them List A and List B.
So List A gets its values from soql query
List<Opportunity> ListA=[select Id, Name from Opportunity where StageName='Claosed Won'];
List<Opportunity> ListB=[select Id,Name from Oppoortunity where Sub_Stage__c='Aawarded'];
Set<Opportunity> SetC=ListA+ListB.
Now I want to combine List A and List B , take out the duplaicate data out of the combination and make a set out of it Set c= List A+ List B ( but it should not have any duplaicate records)
Can anyone please help me with the syntax to join 2 lists into a set?
Please note that due to some limits I cannot get all my data into 1 list . The where clause e/g used above are just for theory . It's bit more complicated than that.
You can iterate over the two lists and filter the records based on the "Id". You may need one more set to filter them. Mark this as the solution, if it solves your problem.
Thanks
All Answers
You can iterate over the two lists and filter the records based on the "Id". You may need one more set to filter them. Mark this as the solution, if it solves your problem.
Thanks
Set has a default uniqueness property which means it will not allow duplicate records to be pushed into the Set. So you can simply add all the elements into the set and it will ensure that only unique records are pushed in. The code would be as below.
Kindly mark it as an answer if that works !