SlideShare uma empresa Scribd logo
1 de 23
営業日ベースで日付を計算してみよう
- プロセスビルダー&フローでこんなことも出来るんだシリーズ -
2018/10/30
Salesforce Developers Meetup #19
石井 智 Satoshi Ishii
サンアンドサンズコンサルティング株式会社
@tasuku_papa0109
Profile
こんなことはありませんか?
ToDoの期日まで余裕がある!・・と思ったら、
期限日が祝日になっていたことに直前で気がついた・・
タイムトリガーでの時間差メール等、年末年始や長期休暇中
にメールが送られ、確認・対応できず・・
土日は数式で対応できるけど、祝日や会社独自のお休み等に
も対応して、日付を計算したい・・
独自のカレンダーを使って
正確な期限を設定したい!
でも・・お高いんでしょう??
(開発しないとダメなんでしょう?)
どっちでもいけます!
(答えになっていない)
全体イメージ
データ作成依頼
(カレンダー計算付)
ToDo
基準日 :2018/10/30
任命先 :鈴木 一郎
件名 :受注後フォローコール依頼(5営業日後)
計算日数:5
期日 :
基準日 :2018/10/30
任命先 :鈴木 一郎
件名 :受注後フォローコール依頼(5営業日後)
計算日数:5
期日 :2018/11/06
任命先 :鈴木 一郎
件名 :受注後フォローコール依頼(5営業日後)
期日 :2018/11/06
状況 :未着手
カスタム
カレンダー
Apexトリガ
or
プロセスビルダー & フロー
プロセスビルダーのみで実装
起動条件:期日が登録されたら
商談
カスタム
オブジェクト
もちろん、応用すれば
他のオブジェクトも可能
例えば・・
商談の受注をトリガーに
レコードを作成
日付
休日フラグ
データ作成依頼
(カレンダー計算付)
今日、お伝えしたい
部分はここ!
必要な材料とスキル
(1)カスタムオブジェクト 2つ
『カスタムカレンダー』 ・・・1日1レコード登録する想定
日付、休日フラグ (例:日付:2018/10/28 休日フラグ:True)
※なので、メンテナンスが必要
『データ作成依頼(カレンダー計算付)』
基準日、計算日数、対象Obj、任命先、件名・・・
(2)プロセスビルダーの知識
条件合致から『データ作成依頼』のレコードを作成
・・・・・・あとは・・
カスタム
カレンダー
データ作成依頼
(カレンダー計算付)
あなたはどちらでしょうか?
Admin or Developer ?
Adminの方
Adminの方は
プロセスビルダーとVisual Workflowで
華麗に解決しちゃいましょう
(3)プロセスビルダーとVisual Workflowの知識
「高速検索」「Sオブジェクト変数」「Sオブジェクトコレクション変数」
「ループ」から「割り当て」
Developerの方
Developerの方はApexトリガ
でゴリゴリと書いちゃいましょう
(3)Apexトリガー開発スキル
before insertトリガ、SELECT文、List型、Map型
Apexトリガーで書くと・・
// カスタムカレンダーから稼働日を取得(前後1年分のみ(計算結果が前後1年間で収まることが前提))
List<Date> businessDateMasterList = new List<Date>();
List<CustomCalendar__c> cc_List;
Date before = (Date.today()) -365;
Date after = (Date.today()) +365;
String sql = ' SELECT Day__c FROM CustomCalendar__c';
sql += ' WHERE WorkingDayFlg__c = True';
sql += ' AND Day__c >=: before';
sql += ' AND Day__c <=: after';
sql += ' ORDER BY Day__c';
cc_List = Database.query(sql);
for(CustomCalendar__c cc : cc_List){
businessDateMasterList.add(cc.Day__c);
}
// 基準値(baseDay)を元に稼働日の日数差と実際の日付を照合するマップの準備
Map<Integer, Date> businessDayMap = new Map<Integer, Date>();
List<Date> pastList = new List<Date>();
Integer futureDateCnt = 1;
for (Date bdate : businessDateMasterList) {
if (bdate < baseDay)
pastList.add(bdate); //過去分を一旦リストに退避
else if (bdate > baseDay)
businessDayMap.put(futureDateCnt++, bdate); // 未来日はカウント値と合わせてマップに格納
}
// 基準日を0として登録
businessDayMap.put(0, baseDay);
// 過去分をマイナス値と紐づけてマップに格納
Integer pastDateCnt = pastList.size();
for (Integer d = 0; d < pastDateCnt; d++) {
Date pastDate = pastList.get(d);
businessDayMap.put(d - pastDateCnt, pastDate);
}
あとは、作成したMapから、基準日からXX日前 or XX日後の営業日を取得し、処理す
るだけ!
処理レコード毎に、基準日毎のマップ作成が必要
(Trigger new から、1レコードずつ取得した後に処理)
トリガー処理内の初回1回のみ実行
基準日が2018/10/30の場合のMap値
:
[ 5 , 2018/11/06]
[ 4 , 2018/11/05]
[ 3 , 2018/11/02]
[ 2 , 2018/11/01]
[ 1 , 2018/10/31]
[ 0 , 2018/10/30]
[ -1 , 2018/10/29]
[ -2 , 2018/10/26]
[ -3 , 2018/10/25]
:
こんな複雑そうなロジック
Visual Workflowで実装出来るのか?
できます!
Adminの方
Visual Workflowで作ると・・
あくまで例ですので、よりエレガントなロジックもあるかと思います
指定日数が
マイナス?
基準日から過去分のカスタムカレンダー
のレコードを取得・リストに格納(降順)
基準日から過去分の
カスタムカレンダーを取得
Sオブジェクトコレクション変
数に格納
カウント値を+1
(インクリメント)
指定日数をプラスに
結果日付に格納
カウント値 = 指定日数?
基準日から未来分のカスタムカレンダー
のレコードを取得・リストに格納(昇順)
基準日から未来分の
カスタムカレンダーを取得
Sオブジェクトコレクション変
数に格納
カウント値を+1
(インクリメント)
結果日付に格納
カウント値 = 指定日数?
『計算基準日となる日付』
『指定日数』
の二つを変数としてプロセスビルダー
から受け取ります
応用すると・・・
翌月の第2営業日までに請求書を送るToDo作成
(基準日を翌月の1日にセットして計算させ、ToDoを発行)
コールセンター業務などで、1次回答期限日、2次回答期限日などを
営業日を考慮した期限を設定する
(エンタイトルメント・マイルストンの時間単位とまでいかないんだけど・・)
Pardotと連携している「キャンペーン」の「キャンペーンメンバー」への追加を調
整し、メール配信タイミングを調整する。
→ Pardotでも平日配信調整は出来るが・・
夏休みや年末年始等、会社独自の長期休暇期間等の配信をさける
・・・等々
補足事項
メリット :Adminさんメンテ可能!
コード書かないからスピード早い(個人差有り)
デメリット:一括大量処理時のガバナーが心配・・(経験上)
DataLoader使う場合はバッチサイズ小さめが安心か
メリット :一括大量処理対策もチューニングの可能
デメリット:コード書く・テストコード・デプロイ・・
どうしてもフローが嫌いな方は、
プロセスビルダー+Apexクラスという実装もあり!?
プロセスビルダー & Visual Workflow
Apexトリガー
伝えたかった事
実現方法はスキルに合わせて選択しましょう!
ロジックの開発(バッチ処理を除く)であれば、
プロセスビルダー&フローで結構複雑な処理までカバーできる!
数式やプロセスビルダーでは収まり切れない複雑な計算ロジック
だが、パターン化は出来る場合、
条件&結果の1セットを「マスタ化」しておき、必要に応じて条
件で検索して、結果を引っ張ってくる・・ような事も可能。
ありがとうございました

Mais conteúdo relacionado

Destaque

Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellSaba Software
 

Destaque (20)

Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
 

20181030 sfdc tokyo_dg_lt_pb_and_flowdaycalc