Ask Search:
Chad FarrellChad Farrell 

create a validation rule on opportunities

I'm trying to create a validation rule that says the following:
 - you cannot open this opportunity(opportunity B) unless
Opportunty A (for the same account) has been closed. 
both Opportunity A and B will be for the same Account.  Opportunity A is the initial record and must be closed first before opening opportunity B.

Can i do this with simple validation rules or would i need to create a process builder?
Best Answer chosen by Chad Farrell
Deepak AnandDeepak Anand
You could do this - 
  1. Create a Rollup Summary field on the Account
    • Type: Rollup Summary
    • Field Label: Number of Opportunities
    • Summarized Object: Opportunity
    • Rollup Type: COUNT
  2. Create another Rollup Summary field on the Account
    • Type: Rollup Summary
    • Field Label: Number of Closed Opportunities
    • Summarized Object: Opportunity
    • Rollup Type: COUNT
    • Filter: 
      IsClosed equals TRUE
  3. Now, you can create a Validation Rule on the Opportunity like as below - 
    AND(
       ISNEW(),
       BLANKVALUE(Account.Number_of_Opportunities, 0) <> 0,
       BLANKVALUE(Account.Number_of_Closed_Opportunities, 0) <
       BLANKVALUE(Account.Number_of_Opportunities, 0)
    )
That should do it.

All Answers

Steve MolisSteve Molis
You could create a simple Validation Rule using a Roll-Up Summary field on the Account Object that returns the Count of Open Opportunties and then throws an Error if there are > 1 Open Opportunity.  That part is easy...  the hard part is gonna be identifying that Opportunity A is the first Opportunity
Swayam ChoukseySwayam Chouksey
+1 Steve,

Please refer to this post for the steps 

https://success.salesforce.com/answers?id=90630000000D8NkAAK

 
Joseph BauerJoseph Bauer
You can create this with a validation rule but you'll need logic from process builder first. Bascially you can have a checkbox on the Account that is false if Opp A is open and true if Opp A is closed. Then on the opportunity you would need a validation rule that first determines that this is Opp B (because the rule doesn't apply for Opp A) and then it checks to see if the account has the opp A field as false. If this is true then through a validation error.
Paras BhattParas Bhatt
Hi,

You can not control view of the record by validation rule.
It will need customization, where your standard view page will be overridden by some intermediate VF page, the page will check the required condition and will display the details or error message based on the result

Regards,
Paras Bhatt
Deepak AnandDeepak Anand
You could do this - 
  1. Create a Rollup Summary field on the Account
    • Type: Rollup Summary
    • Field Label: Number of Opportunities
    • Summarized Object: Opportunity
    • Rollup Type: COUNT
  2. Create another Rollup Summary field on the Account
    • Type: Rollup Summary
    • Field Label: Number of Closed Opportunities
    • Summarized Object: Opportunity
    • Rollup Type: COUNT
    • Filter: 
      IsClosed equals TRUE
  3. Now, you can create a Validation Rule on the Opportunity like as below - 
    AND(
       ISNEW(),
       BLANKVALUE(Account.Number_of_Opportunities, 0) <> 0,
       BLANKVALUE(Account.Number_of_Closed_Opportunities, 0) <
       BLANKVALUE(Account.Number_of_Opportunities, 0)
    )
That should do it.
This was selected as the best answer
Chad FarrellChad Farrell
this looks great... i was about to try this but looks like i'm already at my max of 25 rollup summaries
 
Deepak AnandDeepak Anand
What all Rollups are they ? I suspect we might already have them created :-)
Chad FarrellChad Farrell
actually found some i could delete.  this worked!!