function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
lizmijohnlizmijohn 

Help to monitor product stock

Hi, My requirement is as follows: I have a 'Stock' field in Product page with default value as 1. Once a product is allocated to an opportunity line item, I need a formula or workflow that updates the 'Stock' field in product page to 0. Basically to block the user to select the same product, as it will be blocked for an Account for a certain period. Also user can check the product's 'Stock' field before associating that to a new opportunity line item Is the above possible as I am using Professional Edition. But Workflow & Approval is enabled. Please help. Thanks, Liz
Jeff MayJeff May

When a Product is added to an Opp, you don't actually change the Product record (that would change it for the entire system). Instead, an OpportunityProduct record is created that relates the Product record to the Opp.  The trick for what you need is to track at the Opp level which Products have already been added to the Opp (and then up to the Account).  The only non-progamming way I can think of only works if you have a small number of products.

 

You can create a Opp custom field Roll-up of OppProduct that counts the number of OppProducts, and add a filter for the Product you want to count.   Then do the same at the Account and SUM the Opp rollup field.

 

On the OpportunityProduct, you can define a Validation Rule that says 'if the Rollup count for this product on the Opp is > 0, don't let a new OppProduct be added.

 

OR(AND(Product2.Name = 'A', Opportunity.rollupA__c > 0),    AND(Product2.Name = 'B', Opportunity.rollupB__c > 0))

 

There is a limit to the number of rollup fields you can have on each object so this approach definitely has its limitations.