0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Salesforce】Apexと画面フローで湯婆婆

Posted at

この記事は

SalesforceのApexと画面フローで湯婆婆作って遊んでみたので記録。

実行環境

Trailhead Playground
(言語設定が英語なのであしからず)

作ってみる

Apex

渡された文字列からランダムに一文字返すクラスを作る。

RandomCharAction.apxc
public with sharing class RandomCharAction {
	@InvocableMethod
    public static List<String> getRandomChar(List<String> inputs) {
        List<String> result = new List<String>();
        for(String input : inputs){
        	if (String.isEmpty(input)){
            	result.add('');
            } else {
        		Integer randomIndex = Math.floor(Math.random() * input.length()).intValue();
                System.debug(randomIndex);
        		result.add(input.substring(randomIndex, randomIndex+1));                
            }
    	}
        System.debug(result);
        return result;
    }
}

フロー

下準備

  • Contactのラベルを「従業員」に変更する。(しなくてもいい)
  • Contactにカスタム項目「元の名前」(テキスト型)を作成する。
  • ネットから湯婆婆のイイ感じの画像を拾ってきて静的リソースに登録する。

フロー作成

Flow Builderで画面フローを作成する。
image.png

以下、ざっくり各エレメントの説明。

  • 湯婆婆_input:入力画面。テキスト要素で名前を受け取る。
    image.png

  • 湯婆婆_check:Is Blankで入力が空欄・空白でないかチェック
    (OKの分岐はラベルのNoneをリネームするだけ)
    image.png

  • 湯婆婆_NG:エラー画面。空欄だった場合に突っ返す。
    image.png

  • Assignment:受け取った名前を変数に代入する。
    (テキスト変数の作成が必要)
    image.png

  • RandomCharAction:Apexクラスに変数を渡す。ランダムで1文字ピックアップした新しい名前が返ってくる。
    image.png

  • 従業員追加:従業員(Contact)レコードを追加する。元の名前と新しい名前の両方を登録する。
    image.png

  • 湯婆婆_output:結果画面。元の名前と新しい名前を表示する。
    image.png

動かしてみる

  1. 入力画面
    名前を入れて「契約書を渡す」を押下する。
    image.png

  2. 結果画面
    名前を付けてくれる。
    image.png
    2_1. ボタンについて
    「やり直す」を押下すると名前が入った状態の1の画面が表示される。
    「もう一度」を押下すると何も入っていない状態の1の画面が表示される。
    2_2. レコード作成について
    元の名前と新しい名前が従業員レコードに追加される
    image.png

  3. エラー画面
    1の入力画面で空欄か空白のみを入れるとこうなる。
    「名前を書く」押下で入力画面に戻る。
    image.png

参考

ローコードの便利さが良くわかった湯婆婆でした。おしまい。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?