7

It wasn't (and I assume still isn't?) possible to programmatically set up business hours via Apex code in unit tests:

Is there any mechanism introduced in SFDX that helps with this problem?

(We have 29 tests that fail in a new, bare scratch org and some fail because an 8 hour business day is assumed.)

  • When you deploy code, are you including business hours as part of your package? – Pranay Jaiswal Oct 31 '18 at 17:43
  • @PranayJaiswal No - didn't know that you could... I see that that metadata API came in at version 29.0 and this code was written against version 18.0. Any ideas without the business hours in the package? – Keith C Oct 31 '18 at 17:46
  • Am not sure about API versioning, but if I am not wrong, you can deploy different components with different version numbers like different light components with different version number. So i think it should be fine. Though i never tried to guarantee. – Pranay Jaiswal Oct 31 '18 at 17:52
  • @PranayJaiswal Agreed we could add some business hours to the package as a solution and adjust/mix the API versions. But that means various ripples through e.g. our documentation so I'm wondering if there is an alternate solution? – Keith C Oct 31 '18 at 18:01
5

You can push/pull/deploy/retrieve BusinessHoursSettings as part of your source code repository. You'll find this file in /settings/BusinessHoursSettings.settings-meta.xml. If you're just getting started, you can retrieve it from an org (along with other settings) like this:

sfdx force:source:retrieve -u usernameoralias -m Settings
  • Sounds like what I am looking for. Will work on it now. – Keith C Oct 31 '18 at 18:41
1

As sfdcfox suggests, this stored as settings/BusinessHours.settings-meta.xml in an SFDX project does the trick for me (where I want 8 hours per weekday and zero hours on weekend days):

<?xml version="1.0" encoding="UTF-8"?>
<BusinessHoursSettings xmlns="http://soap.sforce.com/2006/04/metadata">
    <businessHours>
        <active>true</active>
        <default>true</default>
        <fridayEndTime>16:00:00.000Z</fridayEndTime>
        <fridayStartTime>08:00:00.000Z</fridayStartTime>
        <mondayEndTime>16:00:00.000Z</mondayEndTime>
        <mondayStartTime>08:00:00.000Z</mondayStartTime>
        <name>Default</name>
        <thursdayEndTime>16:00:00.000Z</thursdayEndTime>
        <thursdayStartTime>08:00:00.000Z</thursdayStartTime>
        <timeZoneId>America/Los_Angeles</timeZoneId>
        <tuesdayEndTime>16:00:00.000Z</tuesdayEndTime>
        <tuesdayStartTime>08:00:00.000Z</tuesdayStartTime>
        <wednesdayEndTime>16:00:00.000Z</wednesdayEndTime>
        <wednesdayStartTime>08:00:00.000Z</wednesdayStartTime>
    </businessHours>
</BusinessHoursSettings>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.