+ Start a Discussion
Maniraj RoyManiraj Roy 

Compare 3 list of IDs in apex

Hi all,

I have 3 list of account IDs (for 1 sObject is account, for other 2 they are child of account object).

 @AuraEnabled public static List<Account_Reg__c> accNameRegList{get;set;}
 @AuraEnabled public static List<Account_Name__c> accNameList{get;set;}
 @AuraEnabled public static List<Account> accList{get;set;}

I want to compare 3 list of IDs and the get the intersection of those 3 list.
But any of them can come empty also.
  • If 1st & 2nd list is not empty, take intersect of themand return the IDs
  • If 1st, 2nd & 3rd list is not empty take intersect of them and return the IDs
  • If  only one list is not empty , return that list of IDs.
Can you please help me out on this ?
Thanks in advance.
Shukla YogeshShukla Yogesh
Hi Maniraj

List doesn't provide such methods. One way I have tried such scenarios was adding IDs to sets (while querying & using keyset() method). 
In set you can use if else to implement all 3 secarios and using contains() & containsall() methods.

Regards
Yogesh