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
GrifmangGrifmang 

Validation Rule to check checkbox

Good Morning Guys n Gals,

 

  I was wondering if you all could possibly help me with a situation I am running into. I am trying to make my Active Contract field a "live" field if you will. I'll show you the code I have so far, then explain a little more;

 

 

IF (Contract_End_Date__c >= TODAY()) Contract_Start_Date__c <= TODAY() Active_Contract__c = 1,
IF (Contract_Start_Date__c >= TODAY()) Contract_End_Date__c <= TODAY() Active_Contract__c = 0

 

So basically you can see that I want this to check the Active Contract checkbox if the start and end dates on our accounts meet the correct criteria.

 

 I'm pretty new to Salesforce, and seem to be getting syntax errors all over this.

 

Any help would be greatly appreciated.

 

Thanks in advance.

 

Message Edited by Grifmang on 01-21-2010 06:36 AM
Best Answer chosen by Admin (Salesforce Developers) 
Steve :-/Steve :-/

Can you post the exact code that you are using, along with a list of the Field Names and Data Types involved?  I just tested it on my SFDC Dev Org and it worked fine:

 

Start Date: Datatype = Date

End Date: Datatype = Date

Status: Datatype = Formula(Text)  

 

It sounds like some of your fields might be Datatype = Date/Time instead of Date, if that's the case you're going to have to convert them using a DATEVALUE function like this.

 

IF(AND(DATEVALUE(End_Date__c) >= TODAY(), DATEVALUE(Start_Date__c) <= TODAY()), "Active","Inactive")

 

 

 

 

 

Message Edited by Stevemo on 01-21-2010 11:43 AM
Message Edited by Stevemo on 01-21-2010 11:46 AM

All Answers

Steve :-/Steve :-/

You can't create a Formula(Checkbox) field, but you can create a Workflow Rule with a Field update that will evaluate your record and update your Checkbox field from True (checked) to False (unchecked) as needed.  

 

If you do need it to be a formula, then you could try making something other than a Checkbox, and make it a simple Formula(Text) or Formula(Number,0).  Then you could have the formula set the field to "Active", "Inactive", "1", or "0" as needed. 

Message Edited by Stevemo on 01-21-2010 10:45 AM
GrifmangGrifmang

That's exactly what I'm trying to do.

 

Anyway you could point me in the direction of creating a workflow :-" ...

 

I'm pretty new to Salesforce ... heh

 

Thanks again for your help guys n gals.

Steve :-/Steve :-/

Okay, I have a couple of questions about your formula, could you spell out exactly what the conditions are?  It's kind of hard to figure out if you're trying to say something like :

 

IF Contract_End_Date__c >=  TODAY

AND  

Contract_Start_Date__c <=  TODAY

THEN Active_Contract__c  = TRUE

 

Or you're trying to say: 

 

IF Contract_Start_Date__c >= TODAY

OR

Contract_End_Date__c <=  TODAY

THEN Active_Contract__c = FALSE

SalesforceSallySalesforceSally

Create a workflow rule with the following formula

 

AND(EndDate>=TODAY(),StartDate<=TODAY())

 

The update part of the workflow should update "Active Contract" to "True"

Message Edited by SalesforceSally on 01-21-2010 08:00 AM
GrifmangGrifmang

I apologize for not being completely clear.

 

I'm just wanting to make it so if today's date falls into the range on the contract, I.E. Account was signed from 1/1/2010 - 1/1/2011, then the Active Contract box would be checked automatically.

 

So to answer your question Steve, it would be the first example;

IF Contract_End_Date__c >=  TODAY

AND  

Contract_Start_Date__c <=  TODAY

THEN Active_Contract__c  = TRUE

 

I was just a little mistaken, and thought that I had to have another statement to make it false for the opposite.

Steve :-/Steve :-/

If you want it to be completely automatic, and not dependent on a user having to edit or update the record, you could created a Formula(Text) and use something this for the formula:

 

 

IF(AND(End_Date__c >= TODAY(), Start_Date__c <= TODAY()), "Active",

IF(OR(Start_Date__c >= TODAY(), End_Date__c <= TODAY()), "Inactive", NULL

))

 

Line 1 basically says "If the End Date is in the future AND the Start Date is in the past then it's Active"

Line 2 basically says "If the End Date has lapsed OR the Start Date hasn't arrived yet then it's Inactive" 

 

 Looking at your last reply, you could probably shorten it to something like 

 

IF(AND(End_Date__c >= TODAY(), Start_Date__c <= TODAY()), "Active","Inactive")

 

 

 

Message Edited by Stevemo on 01-21-2010 11:15 AM
GrifmangGrifmang

hmm when I try to use that code

 

 

IF(AND(Contract_End_Date__c >= TODAY(), Contract_Start_Date__c <= TODAY()), "Active",

IF(OR(Contract_Start_Date__c >= TODAY(), Contract_End_Date__c <= TODAY()), "Inactive", NULL

))

 It gives me :

Error: Incorrect parameter for function >=(). Expected DateTime, received Date

Same with the shortened code.

 

Message Edited by Grifmang on 01-21-2010 08:21 AM
SalesforceSallySalesforceSally

The date fields are not custom fields. Try this formula

 

IF(AND(EndDate >= TODAY(), StartDate<= TODAY()), "Active","Inactive")

 

Message Edited by SalesforceSally on 01-21-2010 08:24 AM
GrifmangGrifmang
Same issue Sally.
Steve :-/Steve :-/

Can you post the exact code that you are using, along with a list of the Field Names and Data Types involved?  I just tested it on my SFDC Dev Org and it worked fine:

 

Start Date: Datatype = Date

End Date: Datatype = Date

Status: Datatype = Formula(Text)  

 

It sounds like some of your fields might be Datatype = Date/Time instead of Date, if that's the case you're going to have to convert them using a DATEVALUE function like this.

 

IF(AND(DATEVALUE(End_Date__c) >= TODAY(), DATEVALUE(Start_Date__c) <= TODAY()), "Active","Inactive")

 

 

 

 

 

Message Edited by Stevemo on 01-21-2010 11:43 AM
Message Edited by Stevemo on 01-21-2010 11:46 AM
This was selected as the best answer
GrifmangGrifmang

Yeah you are correct. My EndDate/StartDate are date/time fields.

 

So can I use that code you provided with the existing date/time fields or do I need to remake the fields as just date fields ?

 

 

EDIT -- Nvm it works great. THANKS a ton for all the help.

Message Edited by Grifmang on 01-21-2010 10:08 AM
Mahesh Babu Neeli 1Mahesh Babu Neeli 1
Hi All, 

I need a simple checkbox validation.

Fields like,
Is_Mandatory_c --- checkbox
First_Name_c --- text box

Now, i need a validation like:
When the user checked the Is_Mandatory check box, First_Name should be a mandatory field to fill.

So, could you please help on this.