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
Laura Dix-BowlerLaura Dix-Bowler 

Validation rule that references product and opportunity fields

I'm trying to create a validation rule that requires a custom opportunity field to be populated (look up field) before being able to add a specific discount product to the opportunity. Is this possible? 

AND(
  ISBLANK(Ambassador_Referral__c),
  TEXT(Product2.ProductCode, 'REFDISCOUNT')
)

Error: Field Product2 does not exist. Check spelling.
Best Answer chosen by Laura Dix-Bowler
GulshanRajGulshanRaj
Hi Laura,

To get the references of both product and opportunity fields. Please move this validation rule to opportunity product and follow formula mentioned below:
AND(
  ISBLANK(Opportunity.Ambassador_Referral__c),
  Product2.ProductCode='REFDISCOUNT'
)
Please let me know if you have any quesiton.

Thanks & Regards
Gulshan Raj
LinkedIn (https://www.linkedin.com/in/gulshan-raj-a26b0640/)
Twitter (https://twitter.com/gulshan_bittoo)
 

All Answers

GulshanRajGulshanRaj
Hi Laura,

On which object you are creating this validation rule? Is this opportunity or Opportunity product?

Please provide me detail, I will help you.

Thanks & Regards
Gulshan Raj
LinkedIn: https://www.linkedin.com/in/gulshan-raj-a26b0640/
Twitter: https://twitter.com/gulshan_bittoo
Laura Dix-BowlerLaura Dix-Bowler
Hi GulshanRaj, 

This error was on the opportunity. I also tried on the product, but received a similar error msg:

AND(
  ISBLANK(Opportunity.Ambassador_Referral__c),
  TEXT(ProductCode, 'REFDISCOUNT')
)
 Error: Field Opportunity does not exist. Check spelling.

Thank you!
Waqar Hussain SFWaqar Hussain SF
AND(
  ISBLANK(Ambassador_Referral__c),
  (Product2.ProductCode == 'REFDISCOUNT'), 
(Discount > 25)
)

You can use above code, just an example. Can you please elaborate your requirements.
GulshanRajGulshanRaj
Hi Laura,

To get the references of both product and opportunity fields. Please move this validation rule to opportunity product and follow formula mentioned below:
AND(
  ISBLANK(Opportunity.Ambassador_Referral__c),
  Product2.ProductCode='REFDISCOUNT'
)
Please let me know if you have any quesiton.

Thanks & Regards
Gulshan Raj
LinkedIn (https://www.linkedin.com/in/gulshan-raj-a26b0640/)
Twitter (https://twitter.com/gulshan_bittoo)
 
This was selected as the best answer
Laura Dix-BowlerLaura Dix-Bowler
Worked perfectly! Thanks so much