+ Start a Discussion
Frances AllenFrances Allen 

How Do I Create a Validation for Field Level Security Using a Future Date?

The business logic is that all financial information that is classified under Stage 7 is handed over to the finance department on the 10th of the following month. For example, all Stage 7 financial fields of September should be closed on the October 10th. After October 10th, I don't want anyone but finance to have access to a restricted field. Ideally, I like the logic behind this solution:

http://www.salesforcetutorial.com/field-level-security-salesforce/

My psuedo code for this would be
If the month and day of the current month are at the 10th, then all expected payments amount fields for the last month should be locked.
Is there a date function that calculates last month only or am I overthinking and should put something like MONTH() - 1?




 
Best Answer chosen by Frances Allen
Alain CabonAlain Cabon
Hi,

You should use a simple validation rule.

1) New custom field formula, type DATE: label = DATE NEXT MONTH 10

IF (MONTH( date_reference__c ) = 12,                   // if December
    DATE( YEAR( date_reference__c ) + 1, 1, 10),   // then reference date is 10th of January of the next year
    DATE( YEAR( date_reference__c ), MONTH( date_reference__c ) + 1, 10)  // else 10th day of the following month
)

2) New validation rule:

Error Condition Formula :

NOT(OR($Profile.Name = "System Administrator", $Profile.Name = "Company Finance User" ))
&& TODAY() > DATE_NEXT_MONTH_10__c  && ISCHANGED(expected_payments_amount__c)

Error Message: you cannot change the expected payment amount (deadline: the 10th day of the following month)

The field is not read only nor invisible but it can be changed only by some profiles after the 10th day of the following month.

All Answers

Alain CabonAlain Cabon
Hi,

You should use a simple validation rule.

1) New custom field formula, type DATE: label = DATE NEXT MONTH 10

IF (MONTH( date_reference__c ) = 12,                   // if December
    DATE( YEAR( date_reference__c ) + 1, 1, 10),   // then reference date is 10th of January of the next year
    DATE( YEAR( date_reference__c ), MONTH( date_reference__c ) + 1, 10)  // else 10th day of the following month
)

2) New validation rule:

Error Condition Formula :

NOT(OR($Profile.Name = "System Administrator", $Profile.Name = "Company Finance User" ))
&& TODAY() > DATE_NEXT_MONTH_10__c  && ISCHANGED(expected_payments_amount__c)

Error Message: you cannot change the expected payment amount (deadline: the 10th day of the following month)

The field is not read only nor invisible but it can be changed only by some profiles after the 10th day of the following month.
This was selected as the best answer
Frances AllenFrances Allen
This looks like exactly what I was looking for. My only question would be, as a newbie to Salesforce, would I need to define this validation rule for each individual month? The first line references December but would I need to validate payments fields for each month, i.e.
IF(MONTH(date_ref_ _c) = 1 and on and on through the year.
Frances AllenFrances Allen
I just want to follow up that this worked. Absolutely, my concerns were a non-issue.