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
Kanagaraj Arjunan 11Kanagaraj Arjunan 11 

expecting right square bracket, found 'OR'

Hi All

When i save the Apex class it shows error like " expecting right square bracket, found 'OR' " in below i have given the soql query. if anyone konw about this issue please help me.


List<Asset> Assestobj = [SELECTName,Account_Address__c,Account.Name,AccountId,Service_Contract_Provider__c,Product2Id,Product2.Name,Product_Description__c,Lease_Start_Date__c,Actual_End_Date__c,Status from Asset where Lease_Start_Date__c <=: date.today().format() AND  Actual_End_Date__c >=: date.today().format() AND Status ='Active Lease' OR Status= 'Future Lease'];
Thiyagarajan Selvaraj (SFDC Developer)Thiyagarajan Selvaraj (SFDC Developer)
Hi Kanagaraj,

You need to use parentheses to define the order in which fieldExpressions are evaluated.  Change your query like below

List<Asset> Assestobj = [SELECTName,Account_Address__c,Account.Name,AccountId,Service_Contract_Provider__c,Product2Id,Product2.Name,Product_Description__c,Lease_Start_Date__c,Actual_End_Date__c,Status from Asset where (Lease_Start_Date__c <=: date.today().format() AND  Actual_End_Date__c >=: date.today().format()) AND (Status ='Active Lease' OR Status= 'Future Lease')];
surasura
use  TODAY insted of date.today().foramt() refer 
http://www.salesforce.com/us/developer/docs/officetoolkit/Content/sforce_api_calls_soql_select_dateformats.htm
List<Asset> Assestobj =[SELECTName,Account_Address__c,Account.Name,AccountId,Service_Contract_Provider__c,Product2Id,Product2.Name,Product_Description__c,Lease_Start_Date__c,Actual_End_Date__c,Statusfrom Asset where Lease_Start_Date__c <= TODAY AND  Actual_End_Date__c >= TODAY AND (Status ='Active Lease' OR Status= 'Future Lease')];