Skip to main content
David Varney (AnyRoad) a posé une question dans #Formulas

I have a couple validation rules on the opportunity object and I'm wanting to exclude any opps that have Products on the opp where "hardware" is in the name. I've tried adding Product2.Name and OpportunityLineItem.Name to my validation rule but it doesn't work. Is it possible to use the name of a product on an opp in a validation rule? 

 

This is an example of a rule I'm working with:

 

AND (

Probability > 0,

$Profile.Name <> 'System Administrator',

NOT(ISPICKVAL(Type, "Renewal")),

NOT(CONTAINS(OpportunityLineItem.Name, "Hardware")),

ISPICKVAL( Use_Case__c, "" )

)

4 réponses
  1. 21 mars 2023, 22:20

    An Opportunity Validation Rule cannot refer to an Opportunity Line item because there could be 1 or 1000 Opportunity Line items. The Validation Rule would have no way to determine which record to validate against.

     

    You could mark something on the Opportunity like a checkbox through automation if an Opportunity Line Item with Hardware in its name is added or removed from an Opportunity. You could then have your Validation refer to that Opportunity field.

     

    Edit: Another, potentially better, option would be to create a Roll-Up Summary field on the Opportunity with a filter on the Name including Hardware. You could then have your validation trigger off of this being greater than 0.

     

    It looks like you cannot reference the Opportunity Product Name in the Roll-Up criteria, so Flow is the better approach.

0/9000