With this code, when I execute the query in the inspector I get the result, however when I call my class in my component I do not retrieve Data and I get this error in the console:
message : "expecting a right parentheses"
and tells me that the error that exists in the last line of code:
cumul = database.query(Query);
some help please .
@AuraEnabled(cacheable=true)
public static List <AggregateResult> getMonthly(){
User u = [SELECT id, Volume__c FROM User WHERE id=: UserInfo.getUserId()];
List<AggregateResult> cumul = new list<AggregateResult>();
List<Account> acc = [SELECT Id,RecordType.DeveloperName FROM Account WHERE ownerid =: UserInfo.getUserId()];
List<String> accString = new List<String>();
for( Account c: acc)
{
accString.add(c.Id);
}
String year = String.valueOf(System.Today().year());
String productFamily = 'light';
String Filters ='';
Filters = Filters + 'Year__c = \'' + year +'\' ';
Filters = Filters + 'AND Sales__r.Account__r.Station_Account__c IN '+ accString +' ';
Filters = Filters + 'AND Product_Family__c = \''+ productFamily +'\' ';
String Query = 'SELECT Sales__r.Account__r.Name ,CALENDAR_MONTH(Date_technicalfield__c) Month, ';
if (u.Volume__c == 'Liter') {
Query = Query + 'SUM(Quantity_in_L__c) Quantity ';
} else {
Query = Query + 'COUNT(id) Quantity ';
}
Query = Query + 'FROM SalesK__c WHERE ' + Filters + 'GROUP BY Sales__r.Account__r.Name ,Date_technicalfield__c ORDER BY Date_technicalfield__c ASC';
cumul = database.query(Query);
return cumul;
}
system.debug(Query);
to see if there is anything wrong with the way you're building your query.