+ Start a Discussion
lovetolearnlovetolearn 

Save Error: unexpected token: ']'

Hi, 

 

I keep getting this error: 'Save Error: unexpected token: ']'' for this SOQL statement: 

 

SELECT ID FROM Account Where Account_Start_Date__c >: startDate AND
Account_Start_Date__c <: endDate AND Account_Region_Text__c.contains(emplocation)];

 

Not sure where I went wrong wrong. Please help. Thank you. 

Best Answer chosen by Admin (Salesforce Developers) 
AmitSahuAmitSahu

Try :

 

Holiday_Region_Text__c  LIKE : emplocation  

All Answers

AmitSahuAmitSahu
SELECT ID FROM Account Where Account_Start_Date__c >: startDate AND
Account_Start_Date__c <: endDate AND Account_Region_Text__c.contains(emplocation)];
 
I think this one is having some issue.. The line of code you have sent is not complete..
 
Also not sure if contains() will work in SOQL .. You can use LIKE or IN operators.
lovetolearnlovetolearn
trigger testCreateHoliday on Leave_Request__c (after insert) {
    Leave_Request__c insertLR = trigger.new[0];
    Date startDate = insertLR.Request_Start_Date__c;
    System.debug('This is the Date' + startDate);
    Date endDate = insertLR.Request_End_Date__c;
    System.debug('This is the Date' + endDate);
    String emplocation = insertLR.Office_Location__c;
    List<Holiday__c> allHoliday=[SELECT ID FROM Holiday__c Where Holiday_Start_Date__c >: startDate AND Holiday_Start_Date__c <: endDate AND Holiday_Region_Text__c.contains(emplocation)]; 
    Integer x = allHoliday.size();
    List<LR_and_Holiday__c> lrholidaylist = new List<LR_and_Holiday__c>();
    if(x > 0){
        for (Integer i = 1; i<=x; i++){
            LR_and_Holiday__c lrholiday = new LR_and_Holiday__c();
            lrholiday.Leave_Request__c = insertLR.ID;
            lrholiday.Holiday__c = allholiday[(x-1)].ID;
            lrholidaylist.add(lrholiday);
            x--;
        }
        Database.insert(lrholidaylist);
    }
}

 This is my complete code. I used another custom object instead of Account. 

AmitSahuAmitSahu

Try :

 

[SELECT ID FROM Holiday__c Where Holiday_Start_Date__c >: startDate AND Holiday_Start_Date__c <: endDate AND Holiday_Region_Text__c IN:emplocation]    

 

lovetolearnlovetolearn

I get this error: Save Error: IN operator must be used with an iterable expression

AmitSahuAmitSahu

Try :

 

Holiday_Region_Text__c  LIKE : emplocation  

This was selected as the best answer
lovetolearnlovetolearn

Thank you. That worked!!