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
Divya Gupta 11Divya Gupta 11 

Contacts and Orders

Hi,

I've standard contact and custom orders. Now I want to show contacts with all their associated orders with them. Meanwhile, I want show total amount of all orders for that contact too. Any help for the query ?
Praveen KHariPraveen KHari
Since you are mentioned custom orders I believe you have created a new custom object orders not salesforce standard order object. Since you created custom object you can create Contact as a master for order object and use rollup summary field to get total order value in contact and use standard related list in page layout to display order details in contact page layout.
Divya Gupta 11Divya Gupta 11
Well, Thank You. Why I did not think about Roll Up Summary ?. So Now I've made that roll up summary field on contact and total amount is coming for all the orders. But how could I write query for the contacts who doesn't have any orders yet ? Like I need the condition something like this-> select name from contact where orders__r ! = null; How can I write this situation, I do not Understand ?
Divya Gupta 11Divya Gupta 11
Okay one more thing, I cannot use another field, so I need to do aggregation without roll up. Now the problem I'm facing here is - Since aggregation results leads to List, the other fields like mailing street,order_date, etc , I need to define in other query. And for that I would need one more loop for the records. Any Solution ?
Praveen KHariPraveen KHari
 
The best way to do this by creating one more rollup summary field (count of order), since you don’t want to create new field please try something like this.  
 
Select Id, Name from Contact where Id In (Select Contact__c from Order__c)