You need to sign in to do that
Don't have an account?
degmo
Comparing list and produce a final list
Hello All,
I have one big list of accounts as follows:
I have several other smaller lists as follows:
What I need to do is produce a final list. The final list has to start with 'lstMain' and remove from 'lstMain' those that aren't in 'lstVip' or 'lstSpecial' or 'lstNearMe'. What is the most efficient way to accomplish this? Should I use a map instead of a list?
I have one big list of accounts as follows:
List<Account> lstMain = [SELECT Id FROM Account WHERE balance__c > 1000000];
I have several other smaller lists as follows:
List<Account> lstVip = [SELECT Id FROM Account Where vip__c = true]; List<Account>lstSpecial = [SELECT Id FROM Account where special__c = true]; List<Account>lstNearMe = [SELECT Id FROM Account where state =:currentState AND status = 'valid'];
What I need to do is produce a final list. The final list has to start with 'lstMain' and remove from 'lstMain' those that aren't in 'lstVip' or 'lstSpecial' or 'lstNearMe'. What is the most efficient way to accomplish this? Should I use a map instead of a list?
As mentioned you can simply use a map<string,list<Account>> where the string is lstMain/lstVip/lstSpecial/lstNearMe and list values is the respective list of records that are obtained from the above soql queries.
Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks.
You should try to make that logic within the same query so you don't have to manipulate those lists.
I hope this helps.