• Wouter Frankhuizen
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies

Hi,
 

This is a question which I really can't find an answer to. In a trigger before insert or update, I like to compare 4 field values from the object named Calculation__c with 4 field values of Driver_Course__c.

The fields on Calculation__c are named: 

  • Course__c
  • Cup__c
  • Tour__c
  • Driver__c
Those 4 fields i like to compare with the following fields of the object Driver_Course__c:
  • Course__c
  • Course__r.Cup__c
  • Course__r.Cup__r.Tour__c
  • Driver__c
With nested for loops it's easy, but I don't want to run into any governor limits, which I will regarding my test class, which gives me the error: CPU Limits exceeds.

I know how to get the data prepared for matching, but the matching itself I really dont know what to do. After removing and adding stuff this is what i got:
 
public without sharing class AutoFillCalculations {
    public static void FillOut(List<Calculation__c> calcList) {

        // Id nodig van Course
        Set<Id> courseIdSet = new Set<Id>();
        // Id nodig van Cup
        Set<Id> cupIdSet = new Set<Id>();
        //Id nodig van Tour
        Set<Id> tourIdSet = new Set<Id>();
        // Id nodig van Driver
        Set<Id> driverIdSet = new Set<Id>();
        Map<Id, Driver_Course__c> driverCourseById = new Map<Id, Driver_Course__c>();


        // Add the Ids to the sets
        for(Calculation__c calc : calcList){
            courseIdSet.add(calc.Course__c);
            cupIdSet.add(calc.Cup__c);
            tourIdSet.add(calc.Tour__c);
            driverIdSet.add(calc.Driver__c);
        }

        // Query  ids met junction object Driver Course

        for(Driver_Course__c driverCourse : [SELECT Id, Driver__c, Course__c, Course__r.Cup__c, Course__r.Cup__r.Tour__c 
                                               FROM Driver_Course__c 
                                              WHERE Course__c IN :courseIdSet
                                                AND Course__r.Cup__c IN :cupIdSet
                                                AND Course__r.Cup__r.Tour__c IN :tourIdSet
                                                AND Driver__c IN :driverIdSet]){
            driverCourseIdByTourId.put(driverCourse.Id, driverCourse); // is this smart?

        }
        
        for(Calculation__c calc : calcList){

            //??????

        }

        


    }
}


Any help would be much appreciated. 
 

Thanks

Hi,
 

This is a question which I really can't find an answer to. In a trigger before insert or update, I like to compare 4 field values from the object named Calculation__c with 4 field values of Driver_Course__c.

The fields on Calculation__c are named: 

  • Course__c
  • Cup__c
  • Tour__c
  • Driver__c
Those 4 fields i like to compare with the following fields of the object Driver_Course__c:
  • Course__c
  • Course__r.Cup__c
  • Course__r.Cup__r.Tour__c
  • Driver__c
With nested for loops it's easy, but I don't want to run into any governor limits, which I will regarding my test class, which gives me the error: CPU Limits exceeds.

I know how to get the data prepared for matching, but the matching itself I really dont know what to do. After removing and adding stuff this is what i got:
 
public without sharing class AutoFillCalculations {
    public static void FillOut(List<Calculation__c> calcList) {

        // Id nodig van Course
        Set<Id> courseIdSet = new Set<Id>();
        // Id nodig van Cup
        Set<Id> cupIdSet = new Set<Id>();
        //Id nodig van Tour
        Set<Id> tourIdSet = new Set<Id>();
        // Id nodig van Driver
        Set<Id> driverIdSet = new Set<Id>();
        Map<Id, Driver_Course__c> driverCourseById = new Map<Id, Driver_Course__c>();


        // Add the Ids to the sets
        for(Calculation__c calc : calcList){
            courseIdSet.add(calc.Course__c);
            cupIdSet.add(calc.Cup__c);
            tourIdSet.add(calc.Tour__c);
            driverIdSet.add(calc.Driver__c);
        }

        // Query  ids met junction object Driver Course

        for(Driver_Course__c driverCourse : [SELECT Id, Driver__c, Course__c, Course__r.Cup__c, Course__r.Cup__r.Tour__c 
                                               FROM Driver_Course__c 
                                              WHERE Course__c IN :courseIdSet
                                                AND Course__r.Cup__c IN :cupIdSet
                                                AND Course__r.Cup__r.Tour__c IN :tourIdSet
                                                AND Driver__c IN :driverIdSet]){
            driverCourseIdByTourId.put(driverCourse.Id, driverCourse); // is this smart?

        }
        
        for(Calculation__c calc : calcList){

            //??????

        }

        


    }
}


Any help would be much appreciated. 
 

Thanks