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
lovetolearnlovetolearn 

Error: Compile Error: unexpected token: 'startDate' at line 6 column 100

Hi,

 

I am trying to create a trigger that creates mutilple junction object records. I keep getting the following error: Compile Error: unexpected token: 'startDate' at line 6 column 100. Here is my code: 

trigger testCreateHoliday on Leave_Request__c (after update) {
    Leave_Request__c insertLR = new Leave_Request__c();
    Date startDate = insertLR.Request_Start_Date__c;
    Date endDate = insertLR.Request_End_Date__c;
    
    List<Holiday__c> allHoliday=[SELECT ID FROM Holiday__c Where Holiday__c.Holiday_Start_Date__c > startDate];
    insertLR = trigger.new[0];
    List<LR_and_Holiday__c> lrholidaylist = new List<LR_and_Holiday__c>();
    Integer x = 0;
    for (integer i = 0; i<=1; i++){
        LR_and_Holiday__c lrholiday = new LR_and_Holiday__c();
        lrholiday.Leave_Request__c = insertLR.ID;
        lrholiday.Holiday__c = allholiday[x].ID;
        lrholidaylist.add(lrholiday);
        x++;
    }
    Database.insert(lrholidaylist);
}

 Please help. Thank you.

Best Answer chosen by Admin (Salesforce Developers) 
ShamilShamil

I think the problem is with your SOQL:

 

 List<Holiday__c> allHoliday=[SELECT ID FROM Holiday__c Where Holiday__c.Holiday_Start_Date__c > startDate];

 It should be:

 

 List<Holiday__c> allHoliday=[SELECT ID FROM Holiday__c Where Holiday__c.Holiday_Start_Date__c > :startDate];

 

Difference in :startDate

All Answers

ShamilShamil

I think the problem is with your SOQL:

 

 List<Holiday__c> allHoliday=[SELECT ID FROM Holiday__c Where Holiday__c.Holiday_Start_Date__c > startDate];

 It should be:

 

 List<Holiday__c> allHoliday=[SELECT ID FROM Holiday__c Where Holiday__c.Holiday_Start_Date__c > :startDate];

 

Difference in :startDate

This was selected as the best answer
lovetolearnlovetolearn

Thank you.