function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jasjeet GrewalJasjeet Grewal 

Need to compare fields data from two different objects

Hi everyone,

I have two objects Account and Sales.
Account has fields - name, created date, location, payment made.
Sales has fields - date, location, revenue.

I want to compare sum of all payment made by all accounts group by created date and location with revenue from sales object on particular date for same location.
 
for eg: 5 accounts from location A on Mar 01 has sum of 1000 as payment made.
Also on sales object location A on mar 01 should have revenue greater than 1000 or more.

I have tried reports, but I am not successful in getting it solved.

please suggest me possible ideas which I can use to implement this. I am comfortable using apex if needed.
Prabhat Kumar 28Prabhat Kumar 28
You can create custom Visualforce for comparision.
1. Create a wrapper class.
2. Query account Aggregate result to get sum of account based on created date and location.
3. Query Sales based on date and location.
4. Make a list of wrapper class and add the value and wrapper class.
5. Display data on Visualforce page.
6. On VF page you can visualize the data.

You can learn more about wrapper class here.

https://developer.salesforce.com/page/Wrapper_Class
Jasjeet GrewalJasjeet Grewal
Hi Prabhat,

Yes, wrapper class can be solution. But, my main concern is how will be able to use a single query to get data from 2 different objects.

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:
select 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.