Skip to main content
how to show account related opportunity releted product unique record count on account object with trigger.

account -> opportunity -> product

thanks in advance.
2 respuestas
  1. 23 mar 2020, 0:25
    @ayush

    Desk checking the code provided - what happens when there are more than one Opportunity per Account?

    As I read the code, the values in the Account will only reflect the details of the last Opportunity.

    @pankaj

    To resolve the issue you will need to generate a Map<AccountId,Set<ProductIds>> and then set the countField to be the size of the associated Set of Product Ids

    As an aside, I would question the placement of the code on the Opportunity Line Item - it would mean that as you are building the Opportunity, as each line item is inserted, the code will run.  And yet, as an Opportunity is being built, the sale is yet to be achieved, so is there real business value in counting the number of unique product codes if none of the Opportunities are converted to a sale?   And, if we are putting that code to run at this early stage, do we need to consider a Delete trigger?

    Depending on the business need, would a Trigger on the Opportunity once it is "Closed/Won" be a better option?

    Regards

    Andrew

     
0/9000