How can I prevent opportunity validation rule from affecting lead conversion to opportunity? - Answers - Salesforce Trailblazer Community
Trailblazer Community
Ask Search:
Mark GreeneMark Greene 

How can I prevent opportunity validation rule from affecting lead conversion to opportunity?

Hi,

So I created an opportunity validation rule to force users to enter in the text field called "Next Steps" when opportunity stage is not Closed Won or Closed Lost. 

However, this created an error also showed up when converted a lead to an opportunity. I am wondering if I need to map the field? Or can I adjust my rule to make it not apply when converting a lead? 



AND(
OR(NOT(ISPICKVAL(StageName,'Closed Won ')),NOT(ISPICKVAL(StageName,'Closed Lost'))),

ISBLANK(NextStep))
User-added image
Best Answer chosen by Mark Greene
sakshi nagpalsakshi nagpal
Hi Mark,



1- Create a formula field "Lead_Cretaed__c" on Lead and set it to "True". This is to identify if the Opportunity is coming from a Lead Conversion.
2- create a checkbox On Opportunity and don't give it a default value
3- Map the above 2 fields in lead field mapping. 
4- Create a validation rule on Opportunity using the below. 

 
AND(
NOT(ISNEW())
Lead_Created__c,  
TEXT(StageName) <> 'Closed Won',
TEXT(StageName) <> 'Closed Lost,
ISBLANK(NextStep)
)


Thanks,

Sakshi

All Answers

Steve MolisSteve Molis
You could amend it with a NOT(ISNEW()) like this 
 
AND(
NOT(ISNEW())
TEXT(StageName) <> 'Closed Won'
TEXT(StageName) <> 'Closed Lost,
ISBLANK(NextStep)
)

 
Steve MolisSteve Molis
PS.  Otherwise you's need to uncheck Enforce Validation Rules in your Lead Settings 
User-added image

Or create a pair of Checkboxes, one of the Lead (checked) the other on the Opportunity (unchecked) and map them 

Then change your validation rule to something like    
AND(
OR(
AND(
ISNEW(),
Checkbox = FALSE
),
AND(
NOT(ISNEW()),
Checkbox = TRUE
)
),
TEXT(StageName) <> 'Closed Won'
TEXT(StageName) <> 'Closed Lost,
ISBLANK(NextStep)
)

 
sakshi nagpalsakshi nagpal
Hi Mark,



1- Create a formula field "Lead_Cretaed__c" on Lead and set it to "True". This is to identify if the Opportunity is coming from a Lead Conversion.
2- create a checkbox On Opportunity and don't give it a default value
3- Map the above 2 fields in lead field mapping. 
4- Create a validation rule on Opportunity using the below. 

 
AND(
NOT(ISNEW())
Lead_Created__c,  
TEXT(StageName) <> 'Closed Won',
TEXT(StageName) <> 'Closed Lost,
ISBLANK(NextStep)
)


Thanks,

Sakshi

This was selected as the best answer
Mark GreeneMark Greene
Okay so I create the two new checkbox fields and mapped them. However, for the Lead checkbox is that a formula field data type? Also the validation rule says I am missing a ")" somewhere. 
Mark GreeneMark Greene
I get an error. I created the two new checkbox fields on lead and opportunity and have mapped them accordingly. 

AND(
OR(
AND(
ISNEW(),
Checkbox = FALSE
),
AND(
NOT(ISNEW()),
Checkbox = TRUE
)
),
TEXT(StageName) <> 'Closed Won'
TEXT(StageName) <> 'Closed Lost,
ISBLANK(NextStep)
)

User-added image
Mark GreeneMark Greene
The validation rule would be on the opportunity object yes? 
Mark GreeneMark Greene
Sakshi, the formula field is not a checkbox field? What is the formula? Set it to true? =TRUE? Would having the default value for the checkbox checked mean the same thing as TRUE? While unchecked is FALSE?
Steve MolisSteve Molis
Yeah, on the Opportunity 

Sorry, the formula is missing a comma
AND(
OR(
AND(
ISNEW(),
Checkbox = FALSE
),
AND(
NOT(ISNEW()),
Checkbox = TRUE
)
),
TEXT(StageName) <> 'Closed Won',
TEXT(StageName) <> 'Closed Lost,
ISBLANK(NextStep)
)

PS.  Don't just copy & paste formulas
Steve MolisSteve Molis
The Checkbox fields are both Datatype = Checkbox 

The Lead checkbox default value = Checked
The Opportunity checkbox default value = Unchecked

You'll also need to mass update every existing Lead record and update the Checkbox to True/Checked (newly created fields to not auto update on existing records)
Mark GreeneMark Greene

So I got the syntax of the formula working without errors. However, I need to insert my checkbox field I created for the opportunity for both FALSE and TRUE. I am concerned because I did not use the new checkbox field I created on the lead object. Will that cause problems?



User-added image
Mark GreeneMark Greene
I guess am I suppossed to put the lead checkbox field I created and left checked as the default = FALSE and the opportunity checkbox field I leave unchecked = TRUE? 
Steve MolisSteve Molis
Sorry, I don't know what you mean by the last comment  

"However, I need to insert my checkbox field I created for the opportunity for both FALSE and TRUE. I am concerned because I did not use the new checkbox field I created on the lead object. "

On the Lead object you should have created a Checkbox field and set the default value to Checked 

Then you should have mass updated Checkbox field on the existing Leads in your org and set the Checkbox value to TRUE/Checked 

On the Opportunity object you should have created a Checkbox field and set the default value to Unchecked 

Then you should have mapped the Checkbox field on the Lead to the Checkbox field on the Opportunity 

The Validation Rule will now evaluate the Checkbox on the Opportunity object.  If the Opportunity is being created via Lead Convert the record will bypass the Rule on create (but not after). 

If the Opportunity is NOT being created via Lead Convert the record will NOT bypass the Rule on create 
Mark GreeneMark Greene
For the checkbox field to use for ISNEW  = FALSE and NOT(ISNEW =TRUE?

Do I use the field that is the checkbox on the opportunity object or the checkbox on the lead object? 

 
Mark GreeneMark Greene
I named my opportunity checkbox field: "Leave unchecked" and used it for both as you can see in the screenshot. 
Steve MolisSteve Molis
Whut th... who th... whut??? 

ISNEW() is a Function, it literally means "This record is being created and saved to the database for the very first time right now"


 
Mark GreeneMark Greene
I cannot get lead created field inserted on an opportunity validation rule. Unable to cross reference across two objects. 
Mark GreeneMark Greene
On the mass update, I am using data loader and I did get some errors for leads that were already converted. 
Steve MolisSteve Molis
You can ignore them, all you care about is Leads that have yet to be converted
Steve MolisSteve Molis
Dude, you don;t need to put the Lead Checkbox field in the Validation Rule Formula.  You are mapping the Lead checkbox field to the Opportunity checkbox field.  

When the Lead is converted it will pass the Checked/True value from the Lead checkbox to the Opportunity checkbox.  That is how the Validation Rule can check if the Opportunity has been created via Lead convert or not
Mark GreeneMark Greene
Okay,

But I still have a question regarding new opportunity validation rule below: 

The leave unchecked field I created on the opportunity object. Do I use this for both the ISNEW()  = FALSE and the NOT(ISNEW() = TRUE part? 

Or do I use my lead created checkbox field on the lead object? I cannot cross-object reference the lead checkbox. 


User-added image