1

Trying to pass the date value I get an error. How to fix it?

//cmp

...
<aura:attribute name="dateExchangeRates" type="Date"/>
...

//js

getDataForTheDate : function(component, helper){
        let dateExchangeRates = component.get("v.dateExchangeRates");
        if(dateExchangeRates != ''){
            let action = component.get('c.getListExchangeRatesForTheDate');
                action.setParams({"dateExchangeRates" : dateExchangeRates});
                action.setCallback(this, function(response) {
                    let state = response.getState();
                    if (state === "SUCCESS") {
                        //here is my code
                    }
                });
        $A.enqueueAction(action);
        }
    }

//apxc

@AuraEnabled(cacheable=true)
    public static List<Exchange_Rate__c> getListExchangeRatesForTheDate (Date dateExchangeRates){
        String currencys = converter(getListFieldsCurrenciesForRequest());
        return Database.query('SELECT Date__c, Base_Currency__c, ' + currencys + ' FROM Exchange_Rate__c WHERE Date__c = :' + dateExchangeRates);

//error

FATAL_ERROR System.QueryException: unexpected token: '2021-05-30'

1 Answer 1

3

Looks like it is a query exception and has nothing to do with way you are passing in the attributes.

Try using the below

return Database.query('SELECT Date__c, Base_Currency__c, ' + currencys + ' FROM Exchange_Rate__c WHERE Date__c = :dateExchangeRates');

Note apex variables are automatically resolved for you

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .