The DateCalculatorService API allows organizations high-level access to the AdvoLogix date calculation business rules. The following Apex method returns a date based on the parameters supplied.
The following Apex method can be used to compute date via custom coding. Please note that it is always suggested to test your code in the Sandbox.
DateCalculatorService.calculateDate( @selectedAction, @dayCalculatorFunction, @startDate, @endDate, @numCountDays, @numCountMonths, @numCountYears, @selectedBusinessHour, @moveDateWhenNonBusiness );
Required. Provide an action by which the date is to be computed.
Accepted values are ADD, SUBTRACT or COUNT.
Required. Provide whether the date is to be computed using Business Days calculations or Calendar Days calculations.
Accepted values are ‘Calendar Days’, or ‘Business Days’.
Required: Provide the base date from which the target date will be computed. It should be passed as a string in following format YYYY-MM-DD.
Required: Provide an end date upto which the date results are returned. If endDate can be empty string if @selectedAction is not COUNT.
Required: Provide number of days to be added or subtracted from the @startDate.
Required: Provide number of months to be added or subtracted from the @startDate.
Required: Provide number of years to be added or subtracted from the @startDate.
Required: This would help determine how the business days are to be identified.
Accepted values are ‘Weekdays’ or the Record ID of the desired BusinessHour from the organization.
Required: This would help determine the action to be taken when date falls on the non-business day. This option is only used when counting by Calendar Days. Accepted values are ‘ALLOW_NON_BUSINESS_DAY’, ‘SELECT_FOLLOWING_BUSINESS_DAY’, ‘SELECT_PRECEDING_BUSINESS_DAY’
The function call will return a JSON formatted string in this format:
Will be either TRUE or FALSE
Contains the actual date computation results OR Error message if process is hauled with any unexpected error. The date results will include all the necessary information such as Target Date and number of days/months/years between dates etc.
DateCalculatorService.calculateDate( 'ADD', 'Business Days', ‘2018-10-01’, ‘’, 80, 0, 0, 'Weekdays', SELECT_FOLLOWING_BUSINESS_DAY’ );
Add your comment