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
Petercass88Petercass88 

First of month Validation Rule

I have a validation rule that requires the close date to be the first of the month.  So far i have tested the formula to work on every month but December.  I cant figure out where the logic is becoming broken for that month.  Any help?

 

DAY(CloseDate) <>
IF(Month(CloseDate)=12, 31,
DAY(DATE(YEAR(CloseDate),MONTH(CloseDate),1)))

 

Thanks!

Best Answer chosen by Admin (Salesforce Developers) 
kritinkritin

right its very simple...just see the Day of Close Date is 1 or not.

and raise an error message.

All Answers

kritinkritin

Please provide some more examples. What is the exact requirement.?

 

If you require that while creating Oppty record Close Data should be the start Day of month's. Am i correct? then you need to just check the Day should be one nothing else.

 

 

 

 

Petercass88Petercass88

whether creating or updating the close date i would like it to only display the first of the selected month:

 

1/1/11

2/1/11

3/1/11

4/1/11

5/1/11

6/1/11

7/1/11

8/1/11

9/1/11

10/1/11

11/1/11

12/1/11

 

maybe i over-complicated my formula.  Are you suggesting it should be:

DAY(CloseDate) <> Day(1)

kritinkritin

right its very simple...just see the Day of Close Date is 1 or not.

and raise an error message.

This was selected as the best answer
Petercass88Petercass88

Thanks!  I have a nasty habbit of over-complicating things sometimes.

kritinkritin

If you not require to throw an error you can handle it through Opportunity triiger.

 

 

trigger on Opportunity(before update, before insert)

{

for(Opportunity opp: Trigger.New)

{

if(opp.CloseDate!=null)

{

Date clsDate=opp.CloseDate;

integer day=1;

integer month=clsDate.Month();

intger Year=clsDate.Year();

 

Date actualDate= date.newInstance(Year,month,day);

opp.CloseDate=actualDate;

 

}

}

 

}

 

Its very simple.

Petercass88Petercass88

you lost me on this, where do i insert a trigger and what exactly does this function do?  I am not proficient at coding