Getting current product list for an account in Sal

2019-06-02 19:17发布

问题:

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:

  1. Get all the Opportunities for an account
  2. Get all the Products (OpportunityLineItem) for those Opportunities
  3. "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:

  1. Add Product A
  2. Upsell Product A to Product C
  3. Add Product B
  4. 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!

回答1:

I don't think there is any other way than looping through the opportunities to get a list of current products.

You may want to look at creating a custom object to store account to product relationship or you could build a account specific price list that has products related to only that account.