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
Avinash AngasayAvinash Angasay 

Soql/Sosl

1.) Get all the opportunities,contacts,notes related to an Account where Account Name starts with ‘B’.
Ans -select id,Name,(select id, Name,StageName From Opportunities), (Select id from Notes) ,(Select LastName from Contacts) from Account where Name like 'B%'
 
2.) Get the account name,notes,contacts related to an opportunity where opportunity name ends with ‘A’.
Ans-select id,Name,Account.name, (Select id from Notes) ,(Select id from OpportunityContactRoles) from Opportunity where Name like '%A'


Create a map for above,use the queries of  - create all the maps asked below-
Where key will be the account id and list of records as value. It should be like this,
Create 3 maps for opportunities, contacts and notes: Map> Map> Map>
Best Answer chosen by Avinash Angasay
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Avinash,

The code will be as below.
 
Map<id,List<Opportunity>> Oppmap = new Map<id,List<Opportunity>>(); 
Map<id,List<Note>> notmap = new Map<id,List<Note>>(); 
Map<id,List<Contact>> conmap = new Map<id,List<Contact>>(); 
List<Account> AccountList = [select id,Name,(select id, Name,StageName From Opportunities), (Select id from Notes) ,(Select LastName from Contacts) from Account where Name like 'B%'];
for(Account acc : AccountList){
    Oppmap.put(acc.id,acc.Opportunities);  
    notmap.put(acc.id,acc.Notes);
    conmap.put(acc.id,acc.contacts)
}

You have to implement similar way for second one as well.

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,​​​​​​​