You need to sign in to do that
Don't have an account?

SOQL query for current and previous year sales by product.
I have a requirement for creating Data table LWC component. the component look like the following format.
I have written the following query for getting data from salesforce for this table.
SELECT Product__c ,COUNT(Quantity__c),
SUM(CASE
WHEN invoice_date = CALENDAR_YEAR(system.today()) THEN
Total_Price__c
ELSE 0
END) AS "This year Sales" ,
SUM( CASE
WHEN invoice_date = CALENDAR_YEAR(system.today()) - 1 THEN
Total_Price__c
ELSE 0
END) AS "Last year Sales"
FROM Invoice_Lines__c GROUP BY Invoice_Lines__c.Product__c
I am getting 'Unknown error query parsing' error. If i remove the case statements , the query runs without any error. i am not able to figure out the issue with the case statements.
Can anybody suggest how to solve this error or is there any other way i can modify the query? i need a single query to pass the records to the datatable component.
Thanks
Ramya Balakrishnan
I have written the following query for getting data from salesforce for this table.
SELECT Product__c ,COUNT(Quantity__c),
SUM(CASE
WHEN invoice_date = CALENDAR_YEAR(system.today()) THEN
Total_Price__c
ELSE 0
END) AS "This year Sales" ,
SUM( CASE
WHEN invoice_date = CALENDAR_YEAR(system.today()) - 1 THEN
Total_Price__c
ELSE 0
END) AS "Last year Sales"
FROM Invoice_Lines__c GROUP BY Invoice_Lines__c.Product__c
I am getting 'Unknown error query parsing' error. If i remove the case statements , the query runs without any error. i am not able to figure out the issue with the case statements.
Can anybody suggest how to solve this error or is there any other way i can modify the query? i need a single query to pass the records to the datatable component.
Thanks
Ramya Balakrishnan
Where are you running this SOQL? Does it show this error even in developer console/ Workbench with CASE included?
Thanks
Thanks for responding. I am running this SOQL in Developer Console only. Error is in the developer console only.
Thanks
Ramya Balakrishnan