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
aloalo 

Validating whether field is empty

My problem is this.
On opportunities I do not want our salespeople to be able to move the stage field to “close/lost “ unless they have filled out a field that identifies which competitior got the sale.

To identify that we have lost the sale in the stage field I am using the ISPICKVAL(StageName, "Lost ") and then I also need to validate that a custom field (lookup on which competitor) is not empty. Eg. they need to fill this field if stage moves to "lost".

Can anyone tell me how I can do this?
Best Answer chosen by Admin (Salesforce Developers) 
aloalo
Thanks... this worked very well..really helpful

All Answers

JakesterJakester
Hi Alo,

Have you tried the len() function? It returns the length of text in a field, so you could add a condition like

Code:
len(competitor__c)=0

 

tmactmac
I dont know if this is the place for me to post this question but I am having the hardest time writing validation rules.  My problem is that the ones for text fields stump me.  How can I write a validation rule to require that if a text field is complete then you must also complete the picklist field that provides additonal informaton?
aloalo
Thanks... this worked very well..really helpful
This was selected as the best answer
jisaacjisaac
Another way to do it is with dependent dropdown picklists.

When one of our reps marks a deal as Closed Lost, the field Reason Lost becomes required and they have to pick why. We have a different set of reasons in the picklist if the rep chooses Closed Dropped. Since this field is dependent on the stage, it only appears required when the relevant stage is selected.

We also have a list field called Winning Competitor as a dependent dropdown to indicate who did win the deal.

But that only works if you are using picklists. If you are letting them free-form their answers, Jakester's LEN validation rule works perfectly.
bigfat_toe44bigfat_toe44

I am trying to do the exact same thing, but mine doesn't seem to work!  Can you tell me if there is something wrong in my validation rule:

 

AND (
   ISPICKVAL( LeadSource , "CONFERENCE"), 
   LEN( Conference__c ) = 0
)

 

Basically, I want to make sure if someone chooses the "lead source" dropdown as conference, then they have to fill out what the conference was, which is a lookup field.