• Lakshmi Priya 17
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies
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.

Hi there,

 

We are trying to implement a new custom object to store product defects.  We have 1 requirement we are not sure if it requires customization.  The specific requirement is the following:

 

- The ability to relate product defects to each other (ie. records within the same object) by selecting existing defects in the system.

- A *single* related list (eg. "Related Defects") on the product defect layout to show all "linked" product defects, eg. if DefectA is linked to DefectB and DefectC, DefectA's related list will show B and C, DefectB's related list will show A and C, and so on.

 

Can this be done without customization?

 

thanks