[SalesForce] how to get the opportunityproduct fields in opportunity object in validation rule

I want to create a validation rule at "Opportunity" Standard Object to validate the following.

Opp record Type – sample
And Stage not equal to ‘Pending Approval’
Product or product code(item number) ends with -22 or -23 or -24

Then you it should give the following error message.
When requesting samples for 130 Lumen parts, stage should be pending approval.

Can any one help me out how to get the "product code" field in opportunity object in a validation rule.

I Shall appreciate your help.

Best Answer

Step1 :
Create a custom field on 'Opportunity Product'
Type - Number (1,0)
Name - "Lumen Part Code Count"

Step2:
Create a Workflow rule on Opportunity Product with Criteria "OR(RIGHT(Product2.ProductCode,3) == '-23',RIGHT(Product2.ProductCode,3) == '-24', RIGHT(Product2.ProductCode,3) == '-25')" and Everytime record is created.
Write a field update that updates "Lumen Part Code Count" to 1 (Formula Value 1)

Step3:
Create a RollUp Summary field on Opportunity.Name - "Lumen Part Code Sum"
Select Count and "Only records meeting certain criteria should be included in the calculation"
Criteria- Lumen Part Code Count = 1

Step 4 :
Write your validation rule with criteria

 AND(
OR(
$Profile.Name = "Custom Sales User",
$Profile.Name = "Custom Marketing Users 10K 25K"
),
NOT(ISPICKVAL(StageName, "Pending Approval")),
RecordTypeId == '18DigitRecordTypeIdofSample',
Lumen_Part_Code_Sum__c > 0
)


Mention your error message there.

Cheers,

Related Topic