You need to sign in to do that
Don't have an account?
klaus maier
make query more efficient
Hello guys,
i wonder if there is a way to avoid the for loop and make the query more efficient. I still want to query the line items and get a set of account ids.
Is it possible to get a map like <parent.id, opportunityLineItem> ?
Klaus
i wonder if there is a way to avoid the for loop and make the query more efficient. I still want to query the line items and get a set of account ids.
Is it possible to get a map like <parent.id, opportunityLineItem> ?
public static Set<Id> runningMemberships (Date dateField){ Set<Id> idSet = new Set<Id> (); List<OpportunityLineItem> oliList = [ SELECT Id, Opportunity.AccountId FROM OpportunityLineItem WHERE Opportunity.IsWon = true AND Opportunity.start__c <= :dateField AND Opportunity.end__c >= :dateField AND family__c = 'membership'' LIMIT 50000 ]; for (OpportunityLineItem oli : oliList) { idSet.add(oli.Opportunity.AccountId); } return idSet; }Greetings,
Klaus
I dont think that you could avoid the for loop as you need to get all the Account Id here. But if you want to return map which will have information about AccountId and all the Opportunity Line Item related to the corresponding AccountId , then you can try this code . Let me know if you have any doubt . If no doubt then , Please marks this as best answer if it resolves your query.
in that case, a set of ids should be the most efficient way for my future needs. Greetings Klaus