+ Start a Discussion
N.iguN.igu 

Error ”must be of type date and should not be enclosed in quotes”

// WHERE
        private String getWhere(){
            List<String> param = new String[]{ };

            // From
            if(this.obj.IssueDateStart__c <> null){
                Datetime fromDate = adjustJSTtoGMS(obj.IssueDateStart__c);
                param.add('IssueDate__c >= ' + fromDate.format('yyyy-MM-dd\'T\'hh:mm:ss\'Z\''));
            }
            // To
            if(this.obj.IssueDateEnd__c <> null){
                Datetime toDate = adjustJSTtoGMS(obj.IssueDateEnd__c);
                param.add('IssueDate__c <= ' + toDate.format('yyyy-MM-dd\'T\'hh:mm:ss\'Z\''));
            }

            if(param.isEmpty()){
                return '';
            }
            return 'WHERE ' + String.join(param, ' AND ');
        }


        private DateTime adjustJSTtoGMS(DateTime day){
            JST_AM0 = Time.newInstance(15, 0, 0, 0);
            return Datetime.newInstance(day.date(), JST_AM0);
        }
Execution result

value of filter criterion for field 'IssueDate__c' must be of type date and should not be enclosed in quotes



Please tell me the wrong place.




 
Best Answer chosen by N.igu
Ajay K DubediAjay K Dubedi
Hi,

I have gone through your code, implemented the same and found out that if I remove adjustJSTtoGMS(obj.IssueDateStart__c) from line 7 and adjustJSTtoGMS(obj.IssueDateEnd__c) and add simple DateTime.newInstance() from 12 code works. So:

1. Either you have a problem in your adjustJSTtoGMS () method, (little doubt on JST_AM0, try replacing it with Time someVariable),
2. OR There is some problem with format while accessing obj.IssueDateStart__c and corresponding date as well so try printing them before you set.
3. Try commenting out Start and End date (one by one) to have a more significant view to problem.
4. Ensure data type of obj.IssueDateStart__c and obj.IssueDateEnd__c are correct.

Please go through following points (specially the first one) and please update if anything positive happens.
 
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi

All Answers

N.iguN.igu
example
 
// 発行日From
            if(this.obj.IssueDateStart__c != null){
                Datetime fromDate = adjustJSTtoGMS(obj.IssueDateStart__c);
                param.add('IssueDate__c >= '+fromDate.format('2018-02-01'));
            }
            // 発行To
            if(this.obj.IssueDateEnd__c != null){
                Datetime toDate = adjustJSTtoGMS(obj.IssueDateEnd__c);
                param.add('IssueDate__c <= '+toDate.format('2019-07-01'));
            }

not error
Ravi Dutt SharmaRavi Dutt Sharma
Any reason you are using fromDate.format in where clause? You need to pass the fromDate AS IS in the SOQL. format will convert that date into string and in SOQL you should not pass the value of date field as a string. Example query below:

SELECT Id FROM Account WHERE StartDate > fromDate
Ajay K DubediAjay K Dubedi
Hi,

I have gone through your code, implemented the same and found out that if I remove adjustJSTtoGMS(obj.IssueDateStart__c) from line 7 and adjustJSTtoGMS(obj.IssueDateEnd__c) and add simple DateTime.newInstance() from 12 code works. So:

1. Either you have a problem in your adjustJSTtoGMS () method, (little doubt on JST_AM0, try replacing it with Time someVariable),
2. OR There is some problem with format while accessing obj.IssueDateStart__c and corresponding date as well so try printing them before you set.
3. Try commenting out Start and End date (one by one) to have a more significant view to problem.
4. Ensure data type of obj.IssueDateStart__c and obj.IssueDateEnd__c are correct.

Please go through following points (specially the first one) and please update if anything positive happens.
 
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
This was selected as the best answer