Over the last year, I've worked often on various types of integration between our app and Salesforce. One of the things that I found that I to do is figure out a list of all the products that a customer currently has in their account. As near as I can tell, I have to do it this way:
- Get all the Opportunities for an account
- Get all the Products (
OpportunityLineItem
) for those Opportunities - "Add" them together to get the final Product list (current products)
Our sales team makes a new Opportunity
for every sales event for an account (whether it's a new product, an upsell, or a downgrade), so you could theoretically have some opportunities like this:
- Add Product A
- Upsell Product A to Product C
- Add Product B
- Remove Product C
The final result (actual current product list) would be simply Product B. The Opportunities just represent the historical data for all the sales that have been made for this Account
.
I'm a developer. I don't know if this is the best way to go about the sales process -- I leave that to them. However, it is my job to find a list of all the current products so that I can sync that with our billing system automatically. The current way (outlined above) seems clunky and not very useful. It also could get very complicated and it would get hard to scale without making code changes. For instance, if Sales were to add a new product, I'd have to update the code to handle those additions.
Is there any way I can get a list of the current products for an Account
without having to loop through every Opportunity
?
I hope that makes sense. Pseudo-code will work fine, or you can point me to some documentation that I may have missed.
Thanks for your time, guys!