You need to sign in to do that
Don't have an account?
SCh9
Code/Trigger to get count of number of different Product groups, the Assets of each Account belong to at the Account object level
I am trying to achieve a solution for the following problem -
For each Account, I want to know the assets of an account belongs to how many different productGroups (to see products belonging to how varied of product groups each Account(Client) is buying from us)
ProductGroup is a formula field on Assets which gets the value from Products object ( ProductGroup is a picklist on Products)
For example,
If I have, Product groups - P1, P2, P3, P4, P5; Assets - A1, A2, A3, A4 and A1, A2, A4 --> P1 A3 --> P4
I want the count to be 2 because all the assets of this account belongs to 2 different product groups.
From this, I would know Account X is buying our products from 2 productGroups.
My approach - To get the no. of assets in each productGroup, my approach would be for each picklist value in Product Group, using SOQL query , SELECT COUNT(AssetID) from Assets__c GROUP BY Product_Group__c
For each productGroup, get the number of records where the above mentioned countVariable is > 0
Copy this value on to a new custom field(BreadthOfAssets) on Account object.
Am I right?
Do i need to write a trigger on Asset or Account for this and need help in coding this.
Thank you
For each Account, I want to know the assets of an account belongs to how many different productGroups (to see products belonging to how varied of product groups each Account(Client) is buying from us)
ProductGroup is a formula field on Assets which gets the value from Products object ( ProductGroup is a picklist on Products)
For example,
If I have, Product groups - P1, P2, P3, P4, P5; Assets - A1, A2, A3, A4 and A1, A2, A4 --> P1 A3 --> P4
I want the count to be 2 because all the assets of this account belongs to 2 different product groups.
From this, I would know Account X is buying our products from 2 productGroups.
My approach - To get the no. of assets in each productGroup, my approach would be for each picklist value in Product Group, using SOQL query , SELECT COUNT(AssetID) from Assets__c GROUP BY Product_Group__c
For each productGroup, get the number of records where the above mentioned countVariable is > 0
Copy this value on to a new custom field(BreadthOfAssets) on Account object.
Am I right?
Do i need to write a trigger on Asset or Account for this and need help in coding this.
Thank you
You need to write a trigger on asset object :
please check sample code below, I have not tested may be syntax errors will happen.
Hope this helps you.
if above information is informative please mark it as the best answer.
Thanks
Varaprasad