【Tips!】フロー(Flow)で会社の休日・国民の祝日を除く営業日だけ処理を実行する方法

スポンサーリンク

本日のTips!は、標準のフローだけを使って、開発なし(ノンコーティング)で会社の休日(土日・特定休暇)・国民の祝日を判定し、営業日だけ処理実行する方法をご紹介します。

お客様の業務を自動化する場合に、会社の営業日だけ処理を実行したいというご要望がよくありますが、この方法を使えば簡単に実現することができますので、是非マスターしてください。

スポンサーリンク

例えば、毎朝9時に商談の期日が切れているタスクがあるかチェックして、存在する場合には担当者へメール通知するなどの用途があります。

ポイント

  • フロービルダーによるスケジュールトリガーフローの作成方法
  • 組織(会社)の休日・祝日の設定方法
  • フローのロジックによる休日・祝日の判定方法

1.フロービルダーを使って営業日を判定してみよう

今回は、スケジュールトリガーフローを使って、営業日判定処理を作成してみます。もちろんスケジュールトリガー以外のフローでも構いません。

簡単な流れ

  • 組織の休日・国民の祝日を設定(カレンダーを設定)
  • フロービルダーで週末判定処理を作成
  • フロービルダーで祝日判定処理を作成
  • デバッグ実行
  • フローの有効化とスケジュール設定

 

では、一つ一つ手順の内容を解説していきたいと思います。

1.組織の休日・国民の祝日を設定

管理人管理人
まずは会社の設定の休日に祝日を定義しましょう

1.Salesforceにログインして、[設定] からクイック検索で[休日]を検索して実行します。休日設定画面から、[新規]ボタンをクリックして休日登録画面を表示します。

画像をクリックすると拡大できます。

2.休日の詳細画面で、国民の祝日や会社の休日を設定します。

例:休日名:元旦 説明:1月1日を元旦として設定 日付に今年の1月1日をセット 時間は今回は利用しません。

毎年同じ周期の祝日の場合は、繰り返しをチェックして、頻度と繰り返しの開始、終了(任意)時期をセットします。

組織(会社の設定)の休日設定は以上となります。

※会社独自の休日や毎年変わる祝日などは必要な時期にメンテナンスを忘れないように注意が必要です。

2.フロービルダーを使って週末判定処理を作成

続いて、フロービルダーを使って、週末の判定処理を作成しますが、こちらについては、以下の記事で紹介しておりますので、今回は省略します。

以下のフローの部分までは同じ処理となるため、上記記事を参考に作成してから次へお進みください。

サポーターさんサポーターさん
変数の定義もこの後の流れで利用するので忘れずに設定してください

3.フロービルダーで祝日判定処理を作成

週末(土日)判定処理では、週末(土日)の場合に営業日フラグをFalseとしましたが、平日の場合は営業日フラグはデフォルトのTrueのままとなっています。

この後は、平日の場合に組織で定義された休祝日にあたるかどうかを判定する処理を作成していきます。

1.休祝日判定ロジックの追加

平日のプロセスで、レコードの取得処理を追加し以下の内容を定義します。

オブジェクト:休日

条件の要件:なしーすべての休日レコードを取得

並べ替え:なし

保存するレコード数:すべてのレコード

レコードデータの保存方法:すべての項目を自動的に保存 (または項目を選択してあとはsalesforceに任せる)

※取得データが大量になる場合や項目数が多い場合などは、項目を選択してレコード型の変数に割り当てるほうがリソースや性能面からはお勧めします。

今回はテストのため、簡単に設定できる(すべての項目を自動的に保存または項目を選択してあとはsalesforceに任せる)を選択しています。

2.休祝日レコード数分の繰り返し処理を定義

1.で休祝日を取得した後に取得したレコード数分繰り返し処理を定義します。

コレクション変数を選択で、1.で定義したコレクションを選択します。

3.休祝日の条件分岐を作成

取得した休祝日レコードの繰り返し処理の中で、以下の条件分岐を定義します。

結果1:祝日 表示ラベル:祝日 API名は自由に定義してください。

結果を実行する条件の要件:すべての条件に一致(AND)

条件:リソース:現在の日付(フローのCurrentDate) 演算子:次の文字列と一致する

値:ループの現在の項目>休日  ※{!LoopHolidayRecords.ActivityDate}

繰り返し処理の現在の休祝日がフローの実行日と一致する場合は、祝日と判断する

結果2はラベル名だけ営業日としておき、ロジックは不要です。

4.繰り返し処理で休祝日判定された場合に、営業日フラグをFalseに更新する

休祝日判定された場合の後続処理に以下の割り当てを追加し、営業日フラグにFalseをセットします。

変数:BusinessDayFlag(営業日フラグ)

演算子:次の文字列と一致する

値:グローバル変数False

最後に、最初に作成した週末判定処理の条件分岐で週末(土日)のロジックの後続処理を上記の休祝日繰り返し処理の終了プロセスの終了処理とマージします。

以下のようにプロセスを繋げます。

最後のアクションでは営業日判定結果を表示するメモを追加しています。※デバッグ実行で処理結果の詳細を確認するため。

3.デバッグ実行

1.フローを保存したあと、デバッグボタンをクリックします。

フローをデバッグの画面が表示されます。今回作成したフローは特に処理を入れていないためロールバックの必要はありませんが、

データを作成したりするような処理がある場合は、ロールバックオードを利用して既存データに影響しないように実行することもできます。

2.実行結果の確認

デバッグ実行すると処理結果の詳細を確認することができます。上記ではご説明していませんが、以下の図の最後に表示されているような変数の値などを表示するメモを追加するとデバッグしやすくなりますので、ぜひお試しください。

※処理の最後にメモなどのアクションを定義するだけです。

4.フローの有効化とスケジュール設定

1.デバッグ実行で問題がなければ、上記で作成したフローを保存した後、有効化ボタンをクリックしてください。

2.フローを有効化すると、スケジュール済みジョブに実行計画が登録されます。

※スケジュールを変更したい場合は、フローのスケジュールを変更して保存後、有効化することで新しいスケジュールに変更することができます。

サンプルフロー(メタデータ)

本記事でご紹介したフローのメタデータを公開します。

<?xml version="1.0" encoding="UTF-8"?>
<Flow xmlns="http://soap.sforce.com/2006/04/metadata">
    <actionCalls>
        <name>DebugMemo</name>
        <label>営業日判定結果</label>
        <locationX>358</locationX>
        <locationY>1164</locationY>
        <actionName>NewNote</actionName>
        <actionType>quickAction</actionType>
        <inputParameters>
            <name>Title</name>
            <value>
                <stringValue>営業日判定</stringValue>
            </value>
        </inputParameters>
        <inputParameters>
            <name>Body</name>
            <value>
                <stringValue>日付:{!$Flow.CurrentDate} 曜日判定:{!DayOfTheWeekDecimal} 営業日判定:{!BusinessDayFlag}</stringValue>
            </value>
        </inputParameters>
    </actionCalls>
    <apiVersion>50.0</apiVersion>
    <assignments>
        <name>SetBusinessDayFlagFalse</name>
        <label>営業日フラグにFalseをセット</label>
        <locationX>50</locationX>
        <locationY>396</locationY>
        <assignmentItems>
            <assignToReference>BusinessDayFlag</assignToReference>
            <operator>Assign</operator>
            <value>
                <booleanValue>false</booleanValue>
            </value>
        </assignmentItems>
        <connector>
            <targetReference>DebugMemo</targetReference>
        </connector>
    </assignments>
    <assignments>
        <name>SetBusinessDayFlagFalse_0</name>
        <label>営業日フラグにFalseをセット</label>
        <locationX>754</locationX>
        <locationY>756</locationY>
        <assignmentItems>
            <assignToReference>BusinessDayFlag</assignToReference>
            <operator>Assign</operator>
            <value>
                <booleanValue>false</booleanValue>
            </value>
        </assignmentItems>
        <connector>
            <targetReference>LoopHolidayRecords</targetReference>
        </connector>
    </assignments>
    <decisions>
        <description>祝日判定処理</description>
        <name>ConditionJudgementHolidays</name>
        <label>祝日判定処理</label>
        <locationX>886</locationX>
        <locationY>636</locationY>
        <defaultConnector>
            <targetReference>LoopHolidayRecords</targetReference>
        </defaultConnector>
        <defaultConnectorLabel>営業日</defaultConnectorLabel>
        <rules>
            <name>IsHoliday</name>
            <conditionLogic>and</conditionLogic>
            <conditions>
                <leftValueReference>$Flow.CurrentDate</leftValueReference>
                <operator>EqualTo</operator>
                <rightValue>
                    <elementReference>LoopHolidayRecords.ActivityDate</elementReference>
                </rightValue>
            </conditions>
            <connector>
                <targetReference>SetBusinessDayFlagFalse_0</targetReference>
            </connector>
            <label>祝日</label>
        </rules>
    </decisions>
    <decisions>
        <description>週末(土日)判定処理
0:日曜日、6:土曜日</description>
        <name>ConditionJudgementIsWeekend</name>
        <label>週末(土日)判定処理</label>
        <locationX>358</locationX>
        <locationY>276</locationY>
        <defaultConnector>
            <targetReference>GetOrgHolidayRecords</targetReference>
        </defaultConnector>
        <defaultConnectorLabel>平日</defaultConnectorLabel>
        <rules>
            <name>IsWeekend</name>
            <conditionLogic>or</conditionLogic>
            <conditions>
                <leftValueReference>DayOfTheWeekDecimal</leftValueReference>
                <operator>NotEqualTo</operator>
                <rightValue>
                    <numberValue>0.0</numberValue>
                </rightValue>
            </conditions>
            <conditions>
                <leftValueReference>DayOfTheWeekDecimal</leftValueReference>
                <operator>NotEqualTo</operator>
                <rightValue>
                    <numberValue>6.0</numberValue>
                </rightValue>
            </conditions>
            <connector>
                <targetReference>SetBusinessDayFlagFalse</targetReference>
            </connector>
            <label>週末(土日)</label>
        </rules>
    </decisions>
    <formulas>
        <description>曜日判定のための変数</description>
        <name>DayOfTheWeekDecimal</name>
        <dataType>Number</dataType>
        <expression>MOD( {!$Flow.CurrentDate} - DATE(1900, 1, 7), 7)</expression>
        <scale>0</scale>
    </formulas>
    <interviewLabel>営業日判定フロー {!$Flow.CurrentDateTime}</interviewLabel>
    <label>営業日判定フロー</label>
    <loops>
        <name>LoopHolidayRecords</name>
        <label>祝日分繰り返し処理 (LoopHolidayRecords)</label>
        <locationX>666</locationX>
        <locationY>516</locationY>
        <collectionReference>GetOrgHolidayRecords</collectionReference>
        <iterationOrder>Asc</iterationOrder>
        <nextValueConnector>
            <targetReference>ConditionJudgementHolidays</targetReference>
        </nextValueConnector>
        <noMoreValuesConnector>
            <targetReference>DebugMemo</targetReference>
        </noMoreValuesConnector>
    </loops>
    <processMetadataValues>
        <name>BuilderType</name>
        <value>
            <stringValue>LightningFlowBuilder</stringValue>
        </value>
    </processMetadataValues>
    <processMetadataValues>
        <name>CanvasMode</name>
        <value>
            <stringValue>AUTO_LAYOUT_CANVAS</stringValue>
        </value>
    </processMetadataValues>
    <processMetadataValues>
        <name>OriginBuilderType</name>
        <value>
            <stringValue>LightningFlowBuilder</stringValue>
        </value>
    </processMetadataValues>
    <processType>AutoLaunchedFlow</processType>
    <recordLookups>
        <name>GetOrgHolidayRecords</name>
        <label>組織の休日レコード取得</label>
        <locationX>666</locationX>
        <locationY>396</locationY>
        <assignNullValuesIfNoRecordsFound>false</assignNullValuesIfNoRecordsFound>
        <connector>
            <targetReference>LoopHolidayRecords</targetReference>
        </connector>
        <getFirstRecordOnly>false</getFirstRecordOnly>
        <object>Holiday</object>
        <storeOutputAutomatically>true</storeOutputAutomatically>
    </recordLookups>
    <start>
        <locationX>232</locationX>
        <locationY>0</locationY>
        <connector>
            <targetReference>ConditionJudgementIsWeekend</targetReference>
        </connector>
        <schedule>
            <frequency>Once</frequency>
            <startDate>2021-02-14</startDate>
            <startTime>00:00:00.000Z</startTime>
        </schedule>
        <triggerType>Scheduled</triggerType>
    </start>
    <status>Active</status>
    <variables>
        <description>平日判定フラグ</description>
        <name>BusinessDayFlag</name>
        <dataType>Boolean</dataType>
        <isCollection>false</isCollection>
        <isInput>true</isInput>
        <isOutput>true</isOutput>
        <value>
            <booleanValue>true</booleanValue>
        </value>
    </variables>
</Flow>

 

まとめ

いかがでしたでしょうか。説明した手順で設定はうまくいきましたか。

標準機能のフロービルダーを使えば、多くの複雑な処理を自動化することができますが、変数を使ったり条件分岐などのロジックを組む必要があるため、プログラミングに近い作業が必要になります。

ただし、テストクラスを作成する必要がなかったり、コードを書くよりも簡単に短時間で設定して検証できるというのはメリットが大きいと思います。

今回紹介した内容を理解してぜひ実際のプロジェクトで活用してみてください。

スポンサーリンク

「【Tips!】フロー(Flow)で会社の休日・国民の祝日を除く営業日だけ処理を実行する方法」への72件のフィードバック

  1. Hi, I do believe this is a great blog. I stumbledupon it 😉 I am going to come back yet again since i have saved as a favorite it. Money and freedom is the best way to change, may you be rich and continue to help other people.

  2. Aw, this was an exceptionally good post. Finding the time and actual effort to produce a really good article… but what can I say… I procrastinate a whole lot and don’t seem to get nearly anything done.

  3. You’re so cool! I do not believe I’ve truly read anything like that before. So wonderful to discover somebody with unique thoughts on this issue. Seriously.. thank you for starting this up. This website is one thing that’s needed on the internet, someone with a little originality.

  4. I must thank you for the efforts you have put in penning this blog. I really hope to check out the same high-grade blog posts from you later on as well. In fact, your creative writing abilities has inspired me to get my own, personal site now 😉

  5. This is the right blog for everyone who wants to understand this topic. You understand so much its almost tough to argue with you (not that I personally will need to…HaHa). You definitely put a new spin on a subject that’s been written about for many years. Excellent stuff, just wonderful.

  6. Howdy, I think your website could be having internet browser compatibility issues. Whenever I look at your site in Safari, it looks fine however, when opening in IE, it’s got some overlapping issues. I simply wanted to give you a quick heads up! Apart from that, great website.

  7. I was excited to uncover this web site. I need to to thank you for ones time for this fantastic read!! I definitely really liked every part of it and I have you book marked to look at new stuff in your site.

  8. I blog often and I really thank you for your information. This great article has truly peaked my interest. I’m going to book mark your site and keep checking for new information about once per week. I opted in for your RSS feed too.

  9. After I initially commented I appear to have clicked on the -Notify me when new comments are added- checkbox and now every time a comment is added I get 4 emails with the exact same comment. Perhaps there is a way you are able to remove me from that service? Thanks a lot.

  10. Hi! I could have sworn I’ve visited your blog before but after looking at many of the articles I realized it’s new to me. Regardless, I’m certainly delighted I came across it and I’ll be bookmarking it and checking back frequently.

  11. I’m amazed, I must say. Seldom do I come across a blog that’s both educative and interesting, and let me tell you, you have hit the nail on the head. The issue is an issue that not enough men and women are speaking intelligently about. Now i’m very happy I stumbled across this in my hunt for something concerning this.

  12. Good day! I could have sworn I’ve been to this web site before but after looking at a few of the posts I realized it’s new to me. Anyways, I’m certainly happy I stumbled upon it and I’ll be book-marking it and checking back often.

  13. I have to thank you for the efforts you have put in penning this website. I really hope to check out the same high-grade content from you in the future as well. In fact, your creative writing abilities has motivated me to get my own, personal blog now 😉

  14. Howdy! This post couldn’t be written any better! Reading through this post reminds me of my previous roommate! He constantly kept preaching about this. I most certainly will forward this information to him. Fairly certain he’s going to have a great read. Many thanks for sharing!

  15. Hey! Do you know if they make any plugins to help with SEO?
    I’m trying to get my website to rank for some targeted keywords but
    I’m not seeing very good results. If you know of
    any please share. Cheers! I saw similar text here: Eco product

  16. An outstanding share! I have just forwarded this onto a friend who was conducting a little homework on this. And he actually bought me dinner because I stumbled upon it for him… lol. So let me reword this…. Thanks for the meal!! But yeah, thanks for spending the time to talk about this issue here on your website.

  17. Hello there! This blog post could not be written any better! Looking at this article reminds me of my previous roommate! He constantly kept preaching about this. I am going to send this post to him. Fairly certain he’ll have a very good read. Thank you for sharing!

  18. Daga – Introducing to you the most prestigious online entertainment address today. Visit now to experience now!

コメントは受け付けていません。

上部へスクロール