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 OutboxInbox Outbox 

Someone help me with this code, very urgent?

        
1. Write a method that takes in a list of Account Ids.  The method should have the return type: map<Id, map<Id, list<OpportunityLineItem>>>. Each account Id passed in should be mapped to a map of its opportunities mapped to the list of their respective opportunity line items.  Only opportunities with an amount of 500,000 or more should be included in the return.  There is a custom boolean field on the opportunity line item with API name Export_Ignore__c.  If this field is true, the account should be removed from the return map.


2. Write a SOSL statement that returns any leads or contacts where either the first or last name contains ‘cha’.  Both lead and contact results should contain the email address, first name, and last name.  Contacts should also include the account Id.

3. Write a SOQL statement that returns the Id of 10 accounts and all of the opportunity names associated with each account.
Best Answer chosen by Inbox Outbox
Abdul KhatriAbdul Khatri
Hi Inbox,

Here are three different methods, you can change names however you want.
 
//1. Solution
    public static Map<Id, map<Id, List<OpportunityLineItem>>> getList (List<Id> idAccountList)
    {
        
        Map<Id, Map<Id, List<OpportunityLineItem>>> returnVal = new Map<Id, Map<Id, List<OpportunityLineItem>>>();
        Map<Id, List<OpportunityLineItem>> oppLineItemList = new Map<Id, List<OpportunityLineItem>>();
        for(Opportunity opp : [SELECT Id
                                     		, AccountId
                                     		, (SELECT Id FROM OpportunityLineItems)
                                     FROM Opportunity 
                                     WHERE Amount > 500000 
                                    	AND AccountId = :idAccountList AND Account.Export_Ignore__c = false
                              		])
        {
			oppLineItemList.put(opp.Id, opp.OpportunityLineItems);            
            returnVal.put(opp.AccountId, oppLineItemList);
        }
        
        return returnVal;
    }

    //2. Solution    
    public static List<List<SObject>> getSOSL()
    {
    	List<List<SObject>> soslList = [FIND 'cha' IN NAME FIELDS 
                                       		RETURNING Lead(FirstName,LastName,Email), Contact(FirstName,LastName,Email, AccountId)];
        system.debug('soslList ' + soslList);
        return soslList;
    }
    
    //3. Solution    
    public static Map<Id, List<String>> getAccounts()
    {
		Map<Id, List<String>> returnVal = new Map<Id, List<String>>();
        List<String> oppNameList = new List<String>();
        for(Account account : [SELECT Id, (SELECT Name FROM Opportunities) FROM Account LIMIT 10])
        {
            if(account.Opportunities != null && account.Opportunities.size() > 0){
                
                for(Opportunity opp : account.Opportunities){
                    oppNameList.add(opp.Name);
                }
            }
            returnVal.put(account.Id, oppNameList);
        }
        
        return returnVal;
    }