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
Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student 

Help with lookup field filling trigger

Hey there,

My trigger is designed to fill 3 lookup fields upon record creation..however it is not filling the field Bonus_points_out__c.

Please help.

trigger OfficeCommissionOut_GrabReference on Office_Commission__c (before insert) {
Integer monFirstStart = null;
Integer monFirstEnd = null;
Integer monSecondStart = null;
Integer monSecondEnd = null;
Integer monThirdStart = null;
Integer monThirdEnd = null;
ID Office = null;

    //Figure out minimum and maximum date
    for(Office_Commission__c  Off:trigger.new)
    {

        monFirstStart = Off.Commission_Period_Start__c.month()-2;
        monFirstEnd = Off.Commission_Period_End__c.month();
        monSecondStart = Off.Commission_Period_Start__c.month()-1;
        monSecondEnd = Off.Commission_Period_End__c.month()+1;
        monThirdStart = Off.Commission_Period_Start__c.month();
        monThirdEnd = Off.Commission_Period_End__c.month()+2;
 
    Office = Off.Office__c;
   
       
    }
  
    if(monFirstStart!= null && monThirdEnd!= null)
     {  
        //Get all office commission in that range

  List<Commission_Period__c> CommissionPeriods = [Select Id, Point_Calculation_Period_Start__c, Point_Calculation_Period_End__c from Commission_Period__c where CALENDAR_MONTH(Point_Calculation_Period_Start__c)=:monFirstStart and CALENDAR_MONTH(Point_Calculation_Period_End__c)= :monFirstEnd];

        List<Commission_Period__c> CommissionPeriods2 = [Select Id, Point_Calculation_Period_Start__c, Point_Calculation_Period_End__c from Commission_Period__c where CALENDAR_MONTH(Point_Calculation_Period_Start__c)=:monSecondStart and CALENDAR_MONTH(Point_Calculation_Period_End__c)= :monSecondEnd and office__c=:Office];
         List<Commission_Period__c> CommissionPeriods3 = [Select Id, Point_Calculation_Period_Start__c, Point_Calculation_Period_End__c from Commission_Period__c where CALENDAR_MONTH(Point_Calculation_Period_Start__c)=:monThirdStart and CALENDAR_MONTH(Point_Calculation_Period_End__c)= :monThirdEnd and office__c=:Office];



       
        if(CommissionPeriods.size()>0||CommissionPeriods2.size()>0||CommissionPeriods3.size()>0)
        {
            for(Office_Commission__c Off:trigger.new)
            {
               
                if(Off.Point_Calculation_Period_Start__c !=null&&Off.Point_Calculation_Period_End__c !=null)
                {
                    //check if any office commission apply
                    for(Commission_Period__c oc : CommissionPeriods)
                    {
                     
                       
                        Off.Bonus_Points_Out__c = oc.id;
                    
                       break;
              
                   
                    }
                      for(Commission_Period__c oc2 : CommissionPeriods2)
                    {
                      
                       
                        Off.Bonus_Points_Out_2__c = oc2.id;
                        break;
                       
              
                   
                    }
                      for(Commission_Period__c oc3 : CommissionPeriods3)
                    {
                      
                       
                        Off.Bonus_Points_Out_3__c = oc3.id;
                        break;
                       
              
                   
                }
            }
        }
    }
}
}
Best Answer chosen by Developer.mikie.Apex.Student
PeaceMakerPeaceMaker
 Good,  Its time for you to debug the code using debug statement.


trigger OfficeCommission_Grab3 on Office_Commission__c (before insert) {

    // Query all the values from the Commision Period

List<Commission_Period__c> comperiodlist = [Select Id, Point_Calculation_Period_Start__c, Point_Calculation_Period_End__c from Commission_Period__c];


for(Office_Commission__c Off:trigger.new)
{
    for(Commission_Period__c  b:comperiodlist){

// This is for your first If condition , Trying to print all the four values to compare and decide whether it is getting inside the if condition or not. if it is not getting inside the if condition obviously it wont populate the value.

system.debug("Off.Commission_Period_Start__c.month()-2 ------>"+Off.Commission_Period_Start__c.month()-2);
system.debug("b.Point_Calculation_Period_Start__c.month() ------>"+b.Point_Calculation_Period_Start__c.month());
system.debug("Off.Commission_Period_Start__c.month() ------>"+Off.Commission_Period_Start__c.month());
system.debug("b.Point_Calculation_Period_End__c.month() ------>"+b.Point_Calculation_Period_End__c.month());

 if(Off.Commission_Period_Start__c.month()-2  > = b.Point_Calculation_Period_Start__c.month() && Off.Commission_Period_Start__c.month() <= b.Point_Calculation_Period_End__c.month())
            Off.Bonus_Points_Out__c = b.Id;
 

// Similarly do the same for the other IF conditions..

if(Off.Commission_Period_Start__c.month()-1 > = b.Point_Calculation_Period_Start__c.month()  && Off.Commission_Period_End__c.month()+1 <= b.Point_Calculation_Period_End__c.month())
            Off.Bonus_Points_Out_2__c = b.Id;
  

if(Off.Commission_Period_Start__c.month() > = b.Point_Calculation_Period_Start__c.month()  && Off.Commission_Period_End__c.month()+2 <= b.Point_Calculation_Period_End__c.month())
            Off.Bonus_Points_Out_3__c = b.Id;
     }

}

}

All Answers

PeaceMakerPeaceMaker

1. As you are using multiple for loops , values might be overritten. so you better modify the code "For loop section".
2. The best way to address this issue will be Using System.debug statement to see if the select queries returning any values or not.  OR use debug statement inside the for loop see if it is getting inside the for loop.

Mark as Helpful or solved if it helps you to fix..
Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student
Hey PeaceMaker,

Thank you for the reply. I am not exactly sure how I would go about modifying the code to be without the loops and still work the same way.
Would you perhaps be able to walk me through How I can implement your suggestions?

I am still very beginner level when it comes to apex triggers.

Thank you so much for your time.


PeaceMakerPeaceMaker
If my understanding is correct, you have an object called  commission period which stores start and end dates in each record.

x   startdate   enddate
y   startdate   enddate
z   startdate   enddate
d   startdate   enddate
u   startdate   enddate

Based on the date provided in the current record you have to search the commission period table and match the dates to populate the matched commission period Id (x or Y or z,...). am I right.

Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student
Yes that is correct. Office_Commission__c object has three lookup fields, each to the same object (Commission_Period__c)...A way of linking an office commission record to past office commission Records. Sort of a many to many relationship.

Commission Periods come in 3 month sections (from the start of a month and then the end of a month, 3 months after.

Should an office commission record have a date of 01/01/14 - 14/01/14 (They run from 1-14 and then again from 15-28/29/30/31), the three lookups fields bonus_points_out__c, bonus_points_out_2__c and bonus_points_out_3__cwill be filled NOV-JAN, DEC-FEB and JAN-MAR respectively.
PeaceMakerPeaceMaker
Here the problem is to bulkify the code.

Each time you have to query the Commission_Period__c which matches the period to get the corresponding Bonus Point out.

trigger OfficeCommissionOut_GrabReference on Office_Commission__c (before insert) {
Integer monFirstStart = null;
Integer monFirstEnd = null;
Integer monSecondStart = null;
Integer monSecondEnd = null;
Integer monThirdStart = null;
Integer monThirdEnd = null;
ID Office = null;

    //Figure out minimum and maximum date
    for(Office_Commission__c  Off:trigger.new)
    {

        monFirstStart = Off.Commission_Period_Start__c.month()-2;
        monFirstEnd = Off.Commission_Period_End__c.month();
        monSecondStart = Off.Commission_Period_Start__c.month()-1;
        monSecondEnd = Off.Commission_Period_End__c.month()+1;
        monThirdStart = Off.Commission_Period_Start__c.month();
        monThirdEnd = Off.Commission_Period_End__c.month()+2;
 
    Office = Off.Office__c;
   
       
    }

    // Query all the values from the Commision Period

List<Commision_Period__c> comperiodlist = [Select all fields from Commossion period];

Map<String,Id> commap = new Map<String,Id>();

for(Commision_Period__c  b:comperiodlist){

if(start date >= monFirstStart && end date <= monFirstEnd)
commap.put(“monFirstStart”,b.id);
}


  
           for(Office_Commission__c Off:trigger.new)
            {
                        Off.Bonus_Points_Out__c = commap.get(Off.Commission_Period_Start__c.month()-2);  // follow the same for the others
                        Off.Bonus_Points_Out_2__c = oc2.id;
                        Off.Bonus_Points_Out_3__c = oc3.id;
                 }
       }
}
  
Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student
Hey PeaceMaker,

I tried to save the code and it returned : Unexpected Token: All at line 28...do i replace this '' with all the fields that are apart of Commission period. Or is there perhaps a certain way that I fill this part?

Once again, thank you so much for your help
PeaceMakerPeaceMaker
 you have to modify the logic as per your needs as I am not aware of the object schema.  no need all the fields but the required fields.. before modifying and using Maps see how is used and implemented. so that you will get an idea .

Map is a collection of Key and value pairs.  Pass key and get its correcponding values.

1     America
2     Canada
3     Germany

if you pass 1 it will return America,....

First you have to built the Map as per your needs . then you can use in the place where it is required.

Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student
This seems to be exactly what I was looking for when I was first writing the trigger, but i could not find the right thing..perhaps I just didnt understand what I was looking for.

So, something like this:

List<Commision_Period__c> comperiodlist = [Select Id, Point_Calculation_Period_Start__c, Point_Calculation_Period_End__c from Commission_Period__c where CALENDAR_MONTH(Point_Calculation_Period_Start__c)>=:monFirstStart and CALENDAR_MONTH(Point_Calculation_Period_End__c)= :monThirdEnd and office__c=:Office]; ?

I have tried, to work this out..but I keep failing. I am not sure I understand how I would set the map...does it have to be hardcoded? Or can I make it auto-generate the list and keys after I query?

I am currently getting this error:
rror: Compile Error: line 35:11 no viable alternative at character '“' at line 35 column 11


This is the current trigger:

trigger OfficeCommission_Grab3 on Office_Commission__c (before insert) {
Integer monFirstStart = null;
Integer monFirstEnd = null;
Integer monSecondStart = null;
Integer monSecondEnd = null;
Integer monThirdStart = null;
Integer monThirdEnd = null;
ID Office = null;

    //Figure out minimum and maximum date
    for(Office_Commission__c  Off:trigger.new)
    {

        monFirstStart = Off.Commission_Period_Start__c.month()-2;
        monFirstEnd = Off.Commission_Period_End__c.month();
        monSecondStart = Off.Commission_Period_Start__c.month()-1;
        monSecondEnd = Off.Commission_Period_End__c.month()+1;
        monThirdStart = Off.Commission_Period_Start__c.month();
        monThirdEnd = Off.Commission_Period_End__c.month()+2;

    Office = Off.Office__c;
  
      
    }

    // Query all the values from the Commision Period

List<Commision_Period__c> comperiodlist = [Select Id, Point_Calculation_Period_Start__c, Point_Calculation_Period_End__c from Commission_Period__c where CALENDAR_MONTH(Point_Calculation_Period_Start__c)>=:monFirstStart and CALENDAR_MONTH(Point_Calculation_Period_End__c)= :monThirdEnd and office__c=:Office];

Map<String,Id> commap = new Map<String,Id>();

for(Commision_Period__c  b:comperiodlist){

if(b.Point_Calculation_Period_Start__c >= monFirstStart && b.Point_Calculation_Period_End__c  <= monThirdEnd)
commap.put(“monFirstStart”,b.id);
}


 
           for(Office_Commission__c Off:trigger.new)
            {
                        Off.Bonus_Points_Out__c = commap.get(Off.Commission_Period_Start__c.month()-2);  // follow the same for the others
                        Off.Bonus_Points_Out_2__c = oc2.id;
                        Off.Bonus_Points_Out_3__c = oc3.id;
                 }
       }
}

Thank you for your help PeaceMaker




PeaceMakerPeaceMaker
or try without using Map , use something like this....


for(Office_Commission__c Off:trigger.new)
 {
    for(Commision_Period__c  b:comperiodlist){
       if(Off.Commission_Period_Start__c.month()-2  > = b.Point_Calculation_Period_Start__c ) && Off.Commission_Period_Start__c.month) <= b.b.Point_Calculation_Period_End__c)
            Off.Bonus_Points_Out__c = b.Id;
     }

if(Off.Commission_Period_Start__c.month()-1 > = b.Point_Calculation_Period_Start__c ) && Off.Off.Commission_Period_End__c.month()+1 <= b.b.Point_Calculation_Period_End__c)
            Off.Bonus_Points_Out_2__c = b.Id;
     }

if(Off.Commission_Period_Start__c.month() > = b.Point_Calculation_Period_Start__c ) && Off.Commission_Period_End__c.month()+2 <= b.b.Point_Calculation_Period_End__c)
            Off.Bonus_Points_Out_3__c = b.Id;
     }
}


Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student
Hey PeaceMaker,

I am so sorry for being a hassle and I am very appreciative of your help.


I am now getting the error:

Error: Compile Error: Variable does not exist: b.Id at line 39 column 41


This is the current trigger, I took the map out as suggested but could have potentially done it wrong:

trigger OfficeCommission_Grab3 on Office_Commission__c (before insert) {
Integer monFirstStart = null;
Integer monFirstEnd = null;
Integer monSecondStart = null;
Integer monSecondEnd = null;
Integer monThirdStart = null;
Integer monThirdEnd = null;
ID Office = null;

    //Figure out minimum and maximum date
    for(Office_Commission__c  Off:trigger.new)
    {

        monFirstStart = Off.Commission_Period_Start__c.month()-2;
        monFirstEnd = Off.Commission_Period_End__c.month();
        monSecondStart = Off.Commission_Period_Start__c.month()-1;
        monSecondEnd = Off.Commission_Period_End__c.month()+1;
        monThirdStart = Off.Commission_Period_Start__c.month();
        monThirdEnd = Off.Commission_Period_End__c.month()+2;

    Office = Off.Office__c;
  
      
    }

    // Query all the values from the Commision Period

List<Commission_Period__c> comperiodlist = [Select Id, Point_Calculation_Period_Start__c, Point_Calculation_Period_End__c from Commission_Period__c where CALENDAR_MONTH(Point_Calculation_Period_Start__c)>=:monFirstStart and CALENDAR_MONTH(Point_Calculation_Period_End__c)= :monThirdEnd and office__c=:Office];


         for(Office_Commission__c Off:trigger.new)
{
    for(Commission_Period__c  b:comperiodlist){
       if(Off.Commission_Period_Start__c.month()-2  > = b.Point_Calculation_Period_Start__c &&Off.Commission_Period_Start__c.month <= b.b.Point_Calculation_Period_End__c)
            Off.Bonus_Points_Out__c = b.Id;
     }

if(Off.Commission_Period_Start__c.month()-1 > = b.Point_Calculation_Period_Start__c  && Off.Off.Commission_Period_End__c.month()+1 <= b.b.Point_Calculation_Period_End__c)
            Off.Bonus_Points_Out_2__c = b.Id;
     }

if(Off.Commission_Period_Start__c.month() > = b.Point_Calculation_Period_Start__c  && Off.Commission_Period_End__c.month()+2 <= b.b.Point_Calculation_Period_End__c)
            Off.Bonus_Points_Out_3__c = b.Id;
     }


PeaceMakerPeaceMaker
trigger OfficeCommission_Grab3 on Office_Commission__c (before insert) {

    // Query all the values from the Commision Period

List<Commission_Period__c> comperiodlist = [Select Id, Point_Calculation_Period_Start__c, Point_Calculation_Period_End__c from Commission_Period__c];


for(Office_Commission__c Off:trigger.new)
{
    for(Commission_Period__c  b:comperiodlist){
       if(Off.Commission_Period_Start__c.month()-2  > = b.Point_Calculation_Period_Start__c &&Off.Commission_Period_Start__c.month <= b.b.Point_Calculation_Period_End__c)
            Off.Bonus_Points_Out__c = b.Id;
    

if(Off.Commission_Period_Start__c.month()-1 > = b.Point_Calculation_Period_Start__c  && Off.Off.Commission_Period_End__c.month()+1 <= b.b.Point_Calculation_Period_End__c)
            Off.Bonus_Points_Out_2__c = b.Id;
    

if(Off.Commission_Period_Start__c.month() > = b.Point_Calculation_Period_Start__c  && Off.Commission_Period_End__c.month()+2 <= b.b.Point_Calculation_Period_End__c)
            Off.Bonus_Points_Out_3__c = b.Id;
     }

}

}
Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student
The code works the same as the last trigger, probably more reliably with the reduction of redundant statements...but for some reason...the field Bonus_points_out__c still does not fill with the other two.

This is the updated code:

trigger OfficeCommission_Grab3 on Office_Commission__c (before insert) {

    // Query all the values from the Commision Period

List<Commission_Period__c> comperiodlist = [Select Id, Point_Calculation_Period_Start__c, Point_Calculation_Period_End__c from Commission_Period__c];


for(Office_Commission__c Off:trigger.new)
{
    for(Commission_Period__c  b:comperiodlist){
       if(Off.Commission_Period_Start__c.month()-2  > = b.Point_Calculation_Period_Start__c.month() && Off.Commission_Period_Start__c.month() <= b.Point_Calculation_Period_End__c.month())
            Off.Bonus_Points_Out__c = b.Id;
   

if(Off.Commission_Period_Start__c.month()-1 > = b.Point_Calculation_Period_Start__c.month()  && Off.Commission_Period_End__c.month()+1 <= b.Point_Calculation_Period_End__c.month())
            Off.Bonus_Points_Out_2__c = b.Id;
   

if(Off.Commission_Period_Start__c.month() > = b.Point_Calculation_Period_Start__c.month()  && Off.Commission_Period_End__c.month()+2 <= b.Point_Calculation_Period_End__c.month())
            Off.Bonus_Points_Out_3__c = b.Id;
     }

}

}
PeaceMakerPeaceMaker
 Good,  Its time for you to debug the code using debug statement.


trigger OfficeCommission_Grab3 on Office_Commission__c (before insert) {

    // Query all the values from the Commision Period

List<Commission_Period__c> comperiodlist = [Select Id, Point_Calculation_Period_Start__c, Point_Calculation_Period_End__c from Commission_Period__c];


for(Office_Commission__c Off:trigger.new)
{
    for(Commission_Period__c  b:comperiodlist){

// This is for your first If condition , Trying to print all the four values to compare and decide whether it is getting inside the if condition or not. if it is not getting inside the if condition obviously it wont populate the value.

system.debug("Off.Commission_Period_Start__c.month()-2 ------>"+Off.Commission_Period_Start__c.month()-2);
system.debug("b.Point_Calculation_Period_Start__c.month() ------>"+b.Point_Calculation_Period_Start__c.month());
system.debug("Off.Commission_Period_Start__c.month() ------>"+Off.Commission_Period_Start__c.month());
system.debug("b.Point_Calculation_Period_End__c.month() ------>"+b.Point_Calculation_Period_End__c.month());

 if(Off.Commission_Period_Start__c.month()-2  > = b.Point_Calculation_Period_Start__c.month() && Off.Commission_Period_Start__c.month() <= b.Point_Calculation_Period_End__c.month())
            Off.Bonus_Points_Out__c = b.Id;
 

// Similarly do the same for the other IF conditions..

if(Off.Commission_Period_Start__c.month()-1 > = b.Point_Calculation_Period_Start__c.month()  && Off.Commission_Period_End__c.month()+1 <= b.Point_Calculation_Period_End__c.month())
            Off.Bonus_Points_Out_2__c = b.Id;
  

if(Off.Commission_Period_Start__c.month() > = b.Point_Calculation_Period_Start__c.month()  && Off.Commission_Period_End__c.month()+2 <= b.Point_Calculation_Period_End__c.month())
            Off.Bonus_Points_Out_3__c = b.Id;
     }

}

}
This was selected as the best answer
Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student
How do I go about checking the debug after I have entered these statements?

Is this what you meant? I am getting the error: Error: Compile Error: line 14:13 no viable alternative at character '"' at line 14 column 13

Sort of like this:


trigger OfficeCommission_Grab3 on Office_Commission__c (before insert) {

    // Query all the values from the Commision Period

List<Commission_Period__c> comperiodlist = [Select Id, Point_Calculation_Period_Start__c, Point_Calculation_Period_End__c from Commission_Period__c];


for(Office_Commission__c Off:trigger.new)
{
    for(Commission_Period__c  b:comperiodlist){

// This is for your first If condition , Trying to print all the four values to compare and decide whether it is getting inside the if condition or not. if it is not getting inside the if condition obviously it wont populate the value.

system.debug("Off.Commission_Period_Start__c.month()-2 ------>"+Off.Commission_Period_Start__c.month()-2);
system.debug("b.Point_Calculation_Period_Start__c.month() ------>"+b.Point_Calculation_Period_Start__c.month());
system.debug("Off.Commission_Period_Start__c.month() ------>"+Off.Commission_Period_Start__c.month());
system.debug("b.Point_Calculation_Period_End__c.month() ------>"+b.Point_Calculation_Period_End__c.month());

if(Off.Commission_Period_Start__c.month()-2  > = b.Point_Calculation_Period_Start__c.month() && Off.Commission_Period_Start__c.month() <= b.Point_Calculation_Period_End__c.month())
            Off.Bonus_Points_Out__c = b.Id;

system.debug("Off.Commission_Period_Start__c.month()-2 ------>"+Off.Commission_Period_Start__c.month()-2);
system.debug("b.Point_Calculation_Period_Start__c.month() ------>"+b.Point_Calculation_Period_Start__c.month());
system.debug("Off.Commission_Period_Start__c.month() ------>"+Off.Commission_Period_Start__c.month());
system.debug("b.Point_Calculation_Period_End__c.month() ------>"+b.Point_Calculation_Period_End__c.month());

if(Off.Commission_Period_Start__c.month()-1 > = b.Point_Calculation_Period_Start__c.month()  && Off.Commission_Period_End__c.month()+1 <= b.Point_Calculation_Period_End__c.month())
            Off.Bonus_Points_Out_2__c = b.Id;
 
  system.debug("Off.Commission_Period_Start__c.month()-2 ------>"+Off.Commission_Period_Start__c.month()-2);
system.debug("b.Point_Calculation_Period_Start__c.month() ------>"+b.Point_Calculation_Period_Start__c.month());
system.debug("Off.Commission_Period_Start__c.month() ------>"+Off.Commission_Period_Start__c.month());
system.debug("b.Point_Calculation_Period_End__c.month() ------>"+b.Point_Calculation_Period_End__c.month());

if(Off.Commission_Period_Start__c.month() > = b.Point_Calculation_Period_Start__c.month()  && Off.Commission_Period_End__c.month()+2 <= b.Point_Calculation_Period_End__c.month())
            Off.Bonus_Points_Out_3__c = b.Id;
           
            system.debug("Off.Commission_Period_Start__c.month()-2 ------>"+Off.Commission_Period_Start__c.month()-2);
system.debug("b.Point_Calculation_Period_Start__c.month() ------>"+b.Point_Calculation_Period_Start__c.month());
system.debug("Off.Commission_Period_Start__c.month() ------>"+Off.Commission_Period_Start__c.month());
system.debug("b.Point_Calculation_Period_End__c.month() ------>"+b.Point_Calculation_Period_End__c.month());
     }

}

}
PeaceMakerPeaceMaker
1.  replace " with '   in all debug statements

2.  search for debug log in left panel , add your name to it..
3. then run the trigger again , then go back to the debug section
4. you will find a new entry.. open the log , search for "DEBUG" you will find the statements in the huge log with the values...
5. check any you tube video to see how to debug apex class and triggers to get an idea..
Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student

Hey Peacemaker,

Thank you for all your help. I am getting this error:
Error: Compile Error: Arithmetic expressions must use numeric arguments at line 14 column 14 for some strange reason...if I dont put '' around the answer part of the first line of the debug statement which seems to be against what it is designed for....

I have gone through the log and all i have found is a pattern:

Every 4 logs there is one that says: Off.Commission_Period_Start__c.month()-2

Obviously as it would not let me save without the ' ' for some reason...it looks like this (system.debug("Off.Commission_Period_Start__c.month()-2 ------>"+Off.Commission_Period_Start__c.month()-2);)

The next 3 numbers will stay the same for a few lines and then change...except the middle...which I believe is the third statement...always stays as two.

Example:

Off.Commission_Period_Start__c.month()-2 ------>"+Off.Commission_Period_Start__c.month()-2)
4
2
6
(repeated many times, then)
Off.Commission_Period_Start__c.month()-2 ------>"+Off.Commission_Period_Start__c.month()-2)
5
2
7
(repeated mant time, then)
Off.Commission_Period_Start__c.month()-2 ------>"+Off.Commission_Period_Start__c.month()-2)
11
2
1.

I am sorry for being a hassle. But your help as been so amazing..I also feel like I am learning.

Thank you

Elie.RodrigueElie.Rodrigue
Mikie, you need to use single quote, not double quote in your trigger, thats why its not compiling.

system.debug('Off.Commission_Period_Start__c.month()-2 ------>'+Off.Commission_Period_Start__c.month()-2);
instead of system.debug("Off.Commission_Period_Start__c.month()-2 ------>"+Off.Commission_Period_Start__c.month()-2);
Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student
Hey Ellie,

Sorry that was a typo, I did have single quotes...yet for the first line it still says that the line must  use numeric arguments on arithmetic arguments if I remove the quotes from the second half, the rest work:

system.debug('Off.Commission_Period_Start__c.month()-2 ------>'+'Off.Commission_Period_Start__c.month()-2');
system.debug('b.Point_Calculation_Period_Start__c.month() ------>'+b.Point_Calculation_Period_Start__c.month());
system.debug('Off.Commission_Period_Start__c.month() ------>'+Off.Commission_Period_Start__c.month());
system.debug('b.Point_Calculation_Period_End__c.month() ------>'+b.Point_Calculation_Period_End__c.month());

P.S ca you see anything in my code as to why the first lookup field is not being populated?
Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student
Hey guys,
Just an update...the trigger wasnt filling as another trigger was setting the field to null. I have now since fixed this. Thank you all for your help
PeaceMakerPeaceMaker
Good that you made it finally :)