You need to sign in to do that
Don't have an account?
Jasjeet Grewal
wrapper class join two soql queries
Hi all,
I have two objects Account and Sales. Account has fields created date, location, down payment received. Sales has fields date, location, total revenue.
What i am trying to do is to compare sum(down payment received) group by created date and location with total revenue from sales object.
I have made couple of queries wriiten below. I want to use these queries for wrapper class. My main concern now is somehow I want to link both these queries together, so I can view it as table on vf page.
From Account:
This query will give me result for Mar 12 and for all Locations.
Similarly, For Sales object:
This query will give results for sales object.
But, what I wanted is use a single query to get results from both objects.
I would like a data such as following (layout could be little different)
Date Location Down Payment Total Revenue Total Revenue - Down Payment
2018-03-18 Location A 100 100 0
2018-03-18 Location B 150 100 50
Please, let me know how this could be possible.
I have two objects Account and Sales. Account has fields created date, location, down payment received. Sales has fields date, location, total revenue.
What i am trying to do is to compare sum(down payment received) group by created date and location with total revenue from sales object.
I have made couple of queries wriiten below. I want to use these queries for wrapper class. My main concern now is somehow I want to link both these queries together, so I can view it as table on vf page.
From Account:
select sum(down_payment_received__c) from account where created_date__c > 2018-03-12T00:00:00Z and created_date__c < 2018-03-13T00:00:00Z and Location__c in ('Location A', 'Location B', 'Location C', 'Location D') group by Location__c
This query will give me result for Mar 12 and for all Locations.
Similarly, For Sales object:
1select Date__c, Location__c, Total_Revenue_End_of_the_day__c from sales__c where Date__c = 2018-03-12
This query will give results for sales object.
But, what I wanted is use a single query to get results from both objects.
I would like a data such as following (layout could be little different)
Date Location Down Payment Total Revenue Total Revenue - Down Payment
2018-03-18 Location A 100 100 0
2018-03-18 Location B 150 100 50
Please, let me know how this could be possible.
You can try and optimize the queries though. Take out unique location ids from first query and use it in 2nd to further filter the data.
Location here is just a string value from picklist.
If join isnt possible, is there a way I can use list<list> or map to store all data and later use it to display data in vf page?
My bad, I misunderstood it. In that case you have to do separate query. Create a wrapper object will stores all the data for each location. Create a Map <Location, WrapperObject> to store result of first query and use this map to populate data from send query. This is what I can think of right now.