You need to sign in to do that
Don't have an account?
PankajJha
Hi Everyone, how to write trigger how to show account related opportunity releted product unique record count on account object with trigger.
how to show account related opportunity releted product unique record count on account object with trigger.
account -> opportunity -> product
thanks in advance.
account -> opportunity -> product
thanks in advance.
Please create a Trigger on After Insert of OpportunityLineItem. In your Trigger Helper Class Method use the below logic:
If its helpful then mark this as the best solution.
Thanks and Regards
Ayush Sharma
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