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
inbox outbox 7inbox outbox 7 

I want to show account with related opportunities, without using inner query and by using map with either <Id, Sobject>


Map<Id,List<Opportunity>> addOppurnitieswithaccount = new Map<Id,List<Opportunity>>();

Roll up summary kind of thing.

I am just lost. 



Map<Id,List<Account>> acctsWithOpps = new Map<Id,List<Account>>();
System.debug(acctsWithOpps.values());
List<Opportunity> oppl = [SELECT Account.Name, Name FROM Opportunity WHERE Id =: acctsWithOpps.values()];
for(Opportunity opp: acctsWithOpps.values()){
    system.debug(opp.Name);
}.

Please advice. 
 
AnkaiahAnkaiah (Salesforce Developers) 
Hi,

Can you please explain, what is your exact requrement.

Thanks!!
 
inbox outbox 7inbox outbox 7
I want to show account with related opportunities, without using inner query and by using map with either <Id, Sobject>
AnkaiahAnkaiah (Salesforce Developers) 
Hi, 

Try with below code.
 
Map<Id,Opportunity> acctsWithOpps = new Map<Id,Opportunity>();

//Modify the query filter condition as per your need and add required fields
List<Opportunity> oppl = [SELECT Id,AccountId,Name FROM Opportunity where AccountId != NULL limit 10000];
for(Opportunity opp: oppl){
acctsWithOpps.put(opp.AccountId,opp);
}
System.debug('acctsWithOpps=='+acctsWithOpps);
System.debug('acctsWithOpps.values()=='+acctsWithOpps.values());

If this helps, Please mark it as best answer.

Thanks!!​​​​​​​
alex iqbal 6alex iqbal 6
I am also facing same issue on my blog (https://charterspeedtest.info/wow-way-speed-test/)
inbox outbox 7inbox outbox 7
I need to show accounts as well. Show both accounts and opportunities