I am in need of looping through three Objects: Opportunity, OpportunityContactRoles, and a custom object we will call CR__c.
My question is: is it better to write a Wrapper class for these three objects, add the data to a list, and then loop through the list OR if I can do something like this:
for (Opportunity o : SELECT AccountId FROM Opportunity WHERE Id IN :oppStatementsIn) {
for(CR__c cr : SELECT Id, Opportunity__r.AccountId FROM CR__c WHERE Opportunity__c = o.Id){
for(OpportunityContactRole ocr : SELECT Id, ContactId, Role FROM OpportunityContactRole WHERE OpportunityId = o.Id){
When I look at this my immediate reaction is a hard no because of queries inside of for loops. But I am not sure if because of it's structure it is an acceptable way of formatting it. Additionally, there will only ever be 1 - 3 Opportunities to kick off this logic.
Any thoughts on this structure?