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
nmnbawanmnbawa 

Products and opportunities

I have a following business requirement.

We are using products to capture different products that our company offers.

On an opportunity we use a lookup to product to select the product that is bought.

My challege is that there is a total amount on the product that can be sold (total_amount__c), whenever an opportunity is created against a product I want the total amount to reflect 

Total amount - Oppty amount

and show the message to the user if the total product amount is less than 0

Can someone point me in right direction please. If someone can provide trigger code and the test class I would greatly appreciate.

Thanks

sfdcfoxsfdcfox
You can just use a validation rule, such as:

Amount > Total_Amount__c

The validation rule will cause the user to get an error if they go over their allocated amount.