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
shoba shobashoba shoba 

Can we calculate the holidays for an opportunity using visual flow

My scenario is to calculate the holidays for an opportunity.  For this i have created an custom field(DateType: Integer) in opportunity called "Holidayslist__c"(This field i want to display no of holidays).
1.If my opportunity is in "Open" , i want to calculate the holidays between the opportunity CreatedDate field to TODAY.
2.If Opportunity is "Closed", i want to calculate the holidays between the CreatedDate field to ClosedDate.
I wrote a trigger its working , is there anyother option to do this scenario in configuration part like using  visual flow. Can anyone give me suggestion how to do this please.
Ajay K DubediAjay K Dubedi
Hi Shoba

You can do the above work using WorkFlow.Follow the steps below:

1) For this you have to type workflow in quickfind box.
2) Create a Workflow on Opportunity Object and tick on "created, and every time it's edited".
3) Select the criteria as given in Snapshot.
4) Then Add workflow action and select "New fieldUpdate" option and select field to update ="Holidayslist__c".
5) Select "Use a formula to set the new value" and in formula field write following formula:

IF(ISPICKVAL( StageName , "Closed Won" ) ||(ISPICKVAL( StageName , "Closed Lost") ) , CloseDate - DATEVALUE(CreatedDate) ,   TODAY() - DATEVALUE(  CreatedDate ) )

6) Lastly Activate your workflow rule.

User-added image

User-added image

User-added image

User-added image

Regards,
Ajay
Prabhata RathPrabhata Rath
Hi Shoba and Ajay

I have a requirement like we have to calculate working days between two dates (e.g. CONTRACT END DATE and CONTRACT END DATE in a custom object) excluding WEEKENDS and PUBLIC HOLIDAYS. For excluding weekends, there is a formula. But for excluding public holidays ,I am not sure how to write a formula. SO now, I request for your advice. Given below are my questions:
 
1) Which object are you using to register holidays, is it standard "Holiday" object or a custom object.
2) Can you please share the code snippet which you wrote.

Currently to calculate current business day excluding weekends, I am using the formula (retrieved from Salesforce Help) given below:
( 
( FLOOR ( ( TODAY() - DATE (1900,01,01) ) / 7 ) *5 ) 
+ MIN ( 5, MOD ( TODAY() - DATE (1900,01,01), 7 ) +1 ) 
) - 
( 
( FLOOR ( ( DATE(YEAR(TODAY()),MONTH(TODAY()),1) - DATE (1900,01,01) ) / 7 ) *5 ) 
+ MIN ( 5, MOD ( DATE(YEAR(TODAY()),MONTH(TODAY()),1) - DATE (1900,01,01), 7 ) ) 
)
Is there any possibliity to incorporate the logic to exclude public holidays defined either in standard holiday object or custom object.
Waiting for your response.

Thanks in Advance.
Prabhata