0

尝试执行以下操作时出现此错误。我从直接绑定到控制器的 Visualpage 中获取我的截止日期。

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;
4

2 回答 2

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];
于 2013-01-23T15:46:22.583 回答
1
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');
于 2013-01-24T10:58:57.017 回答