Skip to main content

I received a request from a user group to have a validation rule that would force someone to add product B to an opportunity if they added product A (or vise versa). So basically they can add any combination of products A to Z as they please unless they add either A or B in which case the system would force them to add the other one so that any time you have one you also have the other. I know this is tricky due to a couple of reasons the first of which being that they might be forced to use the multi-line view to add products or else it won’t ever work. I also realize that this might require a trigger as opposed to a validation rule (I’m comfortable around apex so that’s not an issue).

I guess I first need to know if the system even adds products as part of a batch when doing multi-line or if they are still added one by one (in which case this all might be moot). Any thoughts?

9 respostas
  1. 28 de nov. de 2012, 19:34
    I can give you a way to do this via validation. The first option will prevent them from saving Product A or Product B without the other (so both products must be added at the same time). The second is based off a secondary action (Opp is won but you can edit it)  that prevents the action if both products are not added (to support adding products separately).

     

    For either option you need to create two roll up summary fields on the Opportunity object that COUNT the number of Product A and number of Product B added to the opportunity.

     

    Option 1.

     

    OR(

     

            AND(

     

                      Product_A_Count__c > 0,

     

                      Product_B_Count__c = 0

     

                    ),

     

            AND(

     

                      Product_A_Count__c = 0,

     

                      Product_B_Count__c > 0

     

                    )

     

    )     

     

    Option 2.

     

    AND(

     

              OR(

     

                      Product_A_Count__c = 0,

     

                      Product_B_Count__c = 0

     

                    ),

     

              IsWon()

     

    )