Here is a link with similar solution.
Requirement: Calculate Due Date from Start Date and Number Of Business Days
Due Date = Start Date + Number of Days [excluding Saturdays and Sundays]
An apex trigger to calculate the Due date on an insert or update is rather time consuming than just creating a formula field with some logic.
The below formula field calculates the Due Date [which is the new formula] provided the Start Date [StartDate__c] and Number Of Days to be added to the Start Date [NumberOfDays__c] excluding Saturdays and Sundays.
CASE(
MOD(StartDate__c - DATE(1900, 1, 7), 7),
0, (StartDate__c) + NumberOfDays__c + FLOOR((NumberOfDays__c-1)/5)*2,
1, (StartDate__c) + NumberOfDays__c + FLOOR((NumberOfDays__c)/5)*2,
2, (StartDate__c) + NumberOfDays__c + FLOOR((NumberOfDays__c+1)/5)*2,
3, (StartDate__c) + NumberOfDays__c + FLOOR((NumberOfDays__c+2)/5)*2,
4, (StartDate__c) + NumberOfDays__c + FLOOR((NumberOfDays__c+3)/5)*2,
5, (StartDate__c) + NumberOfDays__c + CEILING((NumberOfDays__c)/5)*2,
6, (StartDate__c) - IF(NumberOfDays__c>0,1,0) + NumberOfDays__c + CEILING((NumberOfDays__c)/5)*2,
null)
Based on your comments, it sounds like your issue
But right now process builder is running when either of Is_Medicare__pc OR Is_TriCare__pc OR Is_Medicaid__pc is filled AND Person_s_Age__pc >= 65.
may stem from a misunderstanding of how Process Builder criteria that include formula fields work.
You suggested that Person_s_Age__pc
is a formula field based on, presumably, the Birth Date field. Formula fields are calculated each time they're accessed - there's no database event when the calculated value changes. As a result, what your formula:
OR(
OR(
[Account].Is_Medicare__pc,
[Account].Is_TriCare__pc,
[Account].Is_Medicaid__pc
),
AND(
ISNEW(),
NOT(ISBLANK([Account].Person_s_Age__pc)),
[Account].Person_s_Age__pc >= 65
)
)
ultimately does is fire when any of the fields Is_Medicare__pc
, Is_TriCare__pc
, or Is_Medicaid__pc
is changed to true
, or when a new Person Account is created whose Person_s_Age__pc
field at the time of creation is equal to or greater than 65.
If you have a Person Account where any of the fields Is_Medicare__pc
, Is_TriCare__pc
, or Is_Medicaid__pc
is true and that person's birthday passes, making their age hit 65, nothing will happen because that's not a database event.
If you're changing records in the user interface to test this process, the behavior might look like the logic is behaving differently than you expect.
If you want to take action when a person's age ticks over to 65 without a change in the Birth Date field, you would need to either use time-dependent actions in Process Builder or Workflow Rules, or write a Scheduled Apex class to monitor these records.
I personally would probably go the Scheduled Apex route here because I tend to use code-based solutions, but @o-lexi has a clever declarative solution to allow you to do this with an extra formula field via scheduled action in Process Builder.
Best Answer
Since 10 business days are always 14 days (10 business days always include 2 weekends = 4 days), you can greatly simplify by using the following formula: