function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AndrewFisher_TGPAndrewFisher_TGP 

Compare two lists

Hi all,

 

I think my brian is fried as I have been coding all day - I don't even know if I am searching using the correct terminology as I have been jumping between SQL, SOQL, APEX & VB all day...

 

Essentially looking to see if it is possible to compare the results a list collection to the results in another list.

 

As an example - list 1 is generated from the following code:

list<recordType> rT = list<Recordtype>(SELECT ID FROM RecordType  WHERE (Name LIKE '%Standard%' OR Name LIKE '%Parent%')  AND sObjectType = 'Account');

 List 2 is a list of all accounts:

list<Account> ac = list<Account>(SELECT Id, RecordTypeID FROM Account);

 

I know with SOQL you can have a nested query, though in using the 'Database.getQueryLocator' method I seem to be unable to use nested SOQL statements for my batch code...

Best Answer chosen by Admin (Salesforce Developers) 
Jia HuJia Hu
Since the two lists are in the different types, you can't compare them directly.

Make them into the same type, and then use containsAll() method in the Set to compare, doc,
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_set.htm

All Answers

Jia HuJia Hu
Since the two lists are in the different types, you can't compare them directly.

Make them into the same type, and then use containsAll() method in the Set to compare, doc,
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_set.htm
This was selected as the best answer
AndrewFisher_TGPAndrewFisher_TGP

Fantastic - thank you very much!