+ Start a Discussion
shan876shan876 

Validation Rules Help??

I need to write a validation rule that would on the Opportunity ...

If the Probability is greater then 10% then the user must add an OpportunityLineItem (product)...

Could this be done through Validation?

If so how?

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
FleetmanFleetman

Hi Mate,

 

I had the same error and worked out a way. Here it is, this will work

 

AND ( Probability >0.10, NOT(HasOpportunityLineItem))

All Answers

BenPBenP

Yes, you can do that.  It'd be something like this

 

and(probability > 10%, isnull (line item ))

 

Should get you going at least

 

JimRaeJimRae

Because OpportunityLineItem is a child of opportunity, I don't think that will work.

You have 2 options, I can think of.

One, would be to use a trigger to enforce the validation.

On insert or update of the opportunity, if the probabilty is greater than 10%, then query to see if there are any OLI's, if not, use the adderror method call to stop the Opportunity from being saved.

 

The other would be to create a roll-up Summary or other formula field on the Opportunity that indicates that OLI's exist for that Opportunity.  Then your validation rule could work directly against that field.  From a design standpoint, you might get more bang for your buck if you did a rollup counter of the Opportunity Products, in case you wanted to do other analysis of how many lines are on the average deal, etc.

 

 

FleetmanFleetman

Hi Mate,

 

I had the same error and worked out a way. Here it is, this will work

 

AND ( Probability >0.10, NOT(HasOpportunityLineItem))

This was selected as the best answer