• deepthi reddy 24
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
SELECT Id,(SELECT Id FROM Opportunities) FROM Account. This SOQL works but not SELECT Id,(SELECT Id FROM Opportunity) FROM Account. Can anyone explain? Also, SELECT Id FROM Opportunity worked.
Unable to see Launch option in hands on challenge in trailhead Install Apps and Packages in Your Trailhead Playground
Unable to see Launch option in hands on challenge in trailhead Install Apps and Packages in Your Trailhead Playground
Hello guys,

I am trying to do one of the examples in the Apex triggers where a SOQL query is used and I dont understand one of the parameters that is in line 6 which is:

06        [SELECT Id,(SELECT Id FROM Opportunities) FROM Account WHERE Id IN :Trigger.New]);

I dont understand the parameter "IN : Trigger.New])" ??, 

Complete Example:
01trigger AddRelatedRecord on Account(after insert, after update) {
02    List<Opportunity> oppList = new List<Opportunity>();
03     
04    // Get the related opportunities for the accounts in this trigger
05    Map<Id,Account> acctsWithOpps = new Map<Id,Account>(
06        [SELECT Id,(SELECT Id FROM Opportunities) FROM Account WHERE Id IN :Trigger.New]);
07     
08    // Add an opportunity for each account if it doesn't already have one.
09    // Iterate through each account.
10    for(Account a : Trigger.New) {
11        System.debug('acctsWithOpps.get(a.Id).Opportunities.size()=' + acctsWithOpps.get(a.Id).Opportunities.size());
12        // Check if the account already has a related opportunity.
13        if (acctsWithOpps.get(a.Id).Opportunities.size() == 0) {
14            // If it doesn't, add a default opportunity
15            oppList.add(new Opportunity(Name=a.Name + ' Opportunity',
16                                       StageName='Prospecting',
17                                       CloseDate=System.today().addMonths(1),
18                                       AccountId=a.Id));
19        }          
20    }
21 
22    if (oppList.size() > 0) {
23        insert oppList;
24    }
25}



I would really appreciate if anybody can help me. Thanks.