尝试执行以下操作时出现此错误。我从可直接绑定到控制器的可视页面获取截止日期。
QueryException: line 1:322 no viable alternative at character ' '
我的查询正在执行:
Select c.CaseNumber,c.Status,c.ID, Account.Name, Account.Status__c, Account.Type,Account.Location_Type__c,Account.BillingCountry,Contact.Name, Contact.Email FROM Case c where c.BatchNumber__c = 'a0dR0000003dfBbIAI' and c.Deadline_Date__c = 2012-11-16 00:00:00
我的代码:
Date deadline = CaseParameter.Deadline_Date__c;
soql = 'Select c.CaseNumber,c.Status,c.ID, Account.Name, Account.Status__c, Account.Type,Account.Location_Type__c,Account.BillingCountry,Contact.Name, Contact.Email FROM Case c where c.BatchNumber__c = \''+batchNumber+'\'';
soql+= ' and c.Deadline_Date__c = '+deadline;
答案 0 :(得分:2)
您的约会日期应为2012-11-16T00:00:00Z
。注意T分隔符,而不是日期和时间之间的空格。时间组件,并在末尾添加时区指示器(在这种情况下为GMT)
从apex,您可以使用查询绑定功能,而不是构建一个soql字符串,例如。
Date deadline =CaseParameter.Deadline_Date__c;
List<Case> cases = [select caseNumber,id,Account.Name from Case where deadline__date__c=:deadline];
答案 1 :(得分:2)
datetime deadline = datetime.newInstance(CaseParameter.Deadline_Date__c,Time.newInstance(0, 0, 0, 0));
soql = 'Select c.CaseNumber,c.Status,c.ID, Account.Name, Account.Status__c, Account.Type,Account.Location_Type__c,Account.BillingCountry,Contact.Name, Contact.Email FROM Case c where c.BatchNumber__c = \''+batchNumber+'\'';
soql+= ' and c.Deadline_Date__c = '+deadline.format('yyyy-MM-dd');