• ApexLegend
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
I have a Opportunity Trigger Handler were I want to create custom Sportsman__c records related to the created or updated Opportunity. 

In case of Update, to find wheter the updated Opportunity already has Sportsman__c records, i execute the following: 
 
// check if trigger is update
if (oldMap != null) {
	oldRecordList.addAll(oldMap.values());
    System.debug('oldRecordList: ' + oldRecordList);
    // create list with sportsman records related to an opportunity
    sportsmanCheckList = [SELECT Id, Sportsman__c, Opportunity__c FROM Sportsman__c WHERE Opportunity__c IN :oldRecordList];
    System.debug('Checklist: ' + sportsmanCheckList);
    System.debug('oldMap: ' + oldMap);

        for (Opportunity o : oldRecordList) {
        // put opportunities w/o sportsman records in opportunityWithoutSportsmanList
           for (Sportsman__c s : sportsmanCheckList) {
                if (o.Id != s.Opportunity__c) {
               opportunityWithoutSportsmanList.add(o);
                        } 
                    }
                }
The problem is that the sportsmanCheckList never gets filled, I suspect something is wrong with my SOQL query. But when I debug the oldRecordList it contains the updated Opportunity.

Can someone help me with this issue?