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
Mike A SmithMike A Smith 

validation rule issue upon edit

I have this validation rule below which DOES work as intended (1. require the field for ALL NEW Opportunities. 2. require the field during an edit on existing Opportunities that were created after 8/28/21 );

IF(ISNEW(), AND( TODAY() > DATE(2021,08,28), ISPICKVAL( Type ,'No Contract/Upsell'),
ISBLANK(TEXT(NC_U_Reason__c))), AND ( DATEVALUE(CreatedDate) > DATE(2021,08,28),ISBLANK(TEXT(NC_U_Reason__c) )))

But there is this Error that occurs now on a NEW opportunity, can you tell me how to resolve this? 

Problem: With a newer Opportunity created with Type = No Contract/Upsell and NC/U Reason chosen, if I save and then edit the Type, it does not allow me to remove the NC/U Reason.

Error Shown: still gives the VR error message "If you select 'No Contract/Upsell' in Type then the 'NC/U Reason' field is required"


Steps to reproduce:
  1. Create new No Contract/Upsell Opportunity, set NC/U reason to anything
  2. Edit Opportunity Type to something other than No Contract/Upsell. Save.
  3. Attempt to change NC/U Reason to “None” – error results.
Thanks!
Best Answer chosen by Mike A Smith
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Mike ,

Thanks for confirmation. Please update the validation rule as below.
 
IF(ISNEW(), AND( TODAY() > DATE(2021,08,28), ISPICKVAL( Type ,'No Contract/Upsell'),
ISBLANK(TEXT(NC_U_Reason__c))), AND ( DATEVALUE(CreatedDate) > DATE(2021,08,28),ISPICKVAL( Type ,'No Contract/Upsell'),ISBLANK(TEXT(NC_U_Reason__c) )))

If this solution helps, Please mark it as best answer.

Thanks,

All Answers

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Smith,

As per the validation rules , If we are editing a opportunity and saving it with created date >2021,08,28 and NC_U_Reason__c is null the validation rule will fire. 

Can you confirm what should be the behaviour while editing an existing record?

Thanks,
 
Mike A SmithMike A Smith
Thanks Sai. The requester edited a brand new Opportunity and attempted 2 updates...; The Opportunity TYPE is being changed AWAY from 'No Contract/Upsell' (TO 'New Business - FS' for example) .... AND..... The NC/U Reason is changed to 'None' ... So why would it still require the 'NC/U Reason Field' upon save of the edit? Especially with the TYPE no longer being 'No Contract/Upsell' ...?
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Mike,

As per the validation rule

1) if that is a new opportunity and create date is greater than 28/08/2021 and Type  == No Contract/Upsell then NC_U_Reason__c should not be null.

2) If that is exising opportunity and you are editing it such that  created date is greater than 2021,08,28  NC_U_Reason__c  should not be null.

Let us know what you want to edit the validation rule. How should it behave in case of edit?

Thanks,

 
Mike A SmithMike A Smith
The intent was to enforce the field on all newly created Opportunities – AND – on any existing Opportunities with created date > 8/28/21 The requester created a NEW opportunity in the Sandbox (on 9/9/21) to test the above. It looks like the issue is trying to set ‘NC/U Reason’ to NONE. When I look at the Opportunity she was testing with it looks like she DID successfully set the NC/U Reason to a different picklist option as shown below; Type: New Business – FS NC/U Reason: Change Pricing But even NOW if I edit this opportunity as her and just try to set ‘NC/U Reason’ to NONE , WITH the TYPE already set to something different (NOT SET to ‘No Contract/Upsell’) I get the error. So why if the rule shows TYPE='No Contract/Upsell' and the Opportunity does NOT have that value … is the VR still firing? I get that NONE means NULL but the TYPE is no longer is set to the value shown in the VR rule so wouldn’t that alone not make the VR fire?
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Mike,

Help me if my understanding is correct. In case the user edits the opportunity with type as No Contract/Upsell  then only NC_U_Reason__c is required.

NC_U_Reason__c field is not required for other types ?

Thanks,
 
Mike A SmithMike A Smith
Correct, ‘NC/U Reason’ is only required when TYPE=’No Contract/Upsell’. There are 19 total options for TYPE…. One being ‘No Contract/Upsell’. That is the only one that should require the ‘NC/U Reason’ field. So when I edit an opportunity created after 8/28/21 that already shows TYPE=’New Business – FS’ and I try to set ‘NC/U Reason’ to NONE …. I don’t understand why the VR still fires saying ‘When the Type is ‘No Contract/Upsell’ the ‘NC/U Reason’ is required…. The ‘Type’ no longer shows ‘No Contract/Upsell’ on the record….
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Mike ,

Thanks for confirmation. Please update the validation rule as below.
 
IF(ISNEW(), AND( TODAY() > DATE(2021,08,28), ISPICKVAL( Type ,'No Contract/Upsell'),
ISBLANK(TEXT(NC_U_Reason__c))), AND ( DATEVALUE(CreatedDate) > DATE(2021,08,28),ISPICKVAL( Type ,'No Contract/Upsell'),ISBLANK(TEXT(NC_U_Reason__c) )))

If this solution helps, Please mark it as best answer.

Thanks,
This was selected as the best answer