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
gregj777gregj777 

Validation rule or Workflow for Opportunity and Opportunity Products

I am trying to create either a Validation rule or workflow that says:

 

IF(ISPICKVAL(Opportunity_StageName, "Decline"), Product_Return = FALSE, TRUE)

Error message: Please make sure product is checked returned.

This works on the Opportunity Product object but I need it to work when the Opportunity Stage is changed to "Declined" the product get checked returned.

 

OR

Workflow but didn't work either. Anyone have other possible solutuon?

 

 

 

Ritesh AswaneyRitesh Aswaney

Product_Return is custom ? Product_Return__c?

Not really related to your error, but not entirely sure on what you're trying to achieve.

 

If your objective is a field update, then a validation rule wont help

gregj777gregj777

Yes Product return is a custom field created on the Opportunity products object. I want that field to update when the Opportunity_StageName is changed to Decline. 

I tried to create a workflow with field update but it only works if you update the opportunity product object and not just by changing stage to decline. Both do not seem to work to work together.

Here is my workflow:

Rule Name: Mark Product returned on Decline Stage

(Opportunity: StageEQUALSDeclined,Declined(Supplies)) AND (Opportunity Product: Product ReturnEQUALSFalse)

 

Field Update:

Mark Product returned on Decline Stage 

Checkbox options: TRUE

Ritesh AswaneyRitesh Aswaney

Since its a 1:n between Opp - Opp Product, don't reckon you're going to be able to do it via config. Prolly a simple trigger should do it

 

trigger OpportunityAfter on Opportunity (after insert, after update){

 

Id[] oppIds = new Id[]{};

 

for (Opportunity opp : trigger.new)

if('Declined | Declined(Supplies)'.substring(opp.StageName) != -1)

oppIds.add(opp.Id);

 

OpportunityLineItem[] oppLines = new OpportunityLineItem[]{};

 

for(Opportunity oppo : [Select Id, Name, StageName, (Select Id, Name, Product_Return__c from OpportunityLineItems) from Opportunity where Id in :oppIds]){

 

for (OpportunityLineItem oli : oppo.OpportunityLineItems){

if(!oli.Product_Return__c){

oli.Product_Return__c = true;

oppLines.add(oli);

}//end if

}//end oli

 

} //end opps

 

if(oppLines != null && !oppLines.isEmpty())

Database.update(oppLines);

 

}