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?

More than 1 year has passed since last update.

Salesforceでフローを作成しよう~リードの項目更新を起点に自動で「取引開始済み」する~

Posted at

こんにちは
本橋孝昭です

今回は
・リードの項目を更新したら自動で取引開始済みになり取引先、取引先責任者作成

のフローを作成します
(今回は例としてリード標準項目「評価」が「Hot」になった場合自動で取引開始済みになり取引先、取引先責任者作成をします)

今回の内容はこちらの記事を参考にしました
https://blog.cloudanalogy.com/salesforce-lead-conversion-using-flow/

設定は大きく2つです
1 Apexを作成しよう
2 フローを作成しよう

では、1 Apexを作成しよう から説明します

1 Apexを作成しよう

Apex作成方法は以下の通りです

・ステップ1 歯車マーク設定から「開発者コンソール」クリック

・ステップ2 File→New→Apex Class をクリック 名前を付けてOKをクリック

・ステップ3 以下のコードを記載し「Save」

public class AutoConvertLeads1 {

    @InvocableMethod(label = 'Auto Convert Leads')

    public static void LeadAssign(List<Requests> requestList) {

        LeadStatus CLeadStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted = true LIMIT 1];

        List<Database.LeadConvert> MassLeadconvert = new List<Database.LeadConvert>();

        for (Requests req : requestList) {

            Database.LeadConvert Leadconvert = new Database.LeadConvert();

            Leadconvert.setLeadId(req.LeadId);

            String accountId = req.AccountId; // Assuming you have a field called "Account_ID__c" in the Requests class

            if (accountId != null) {

                Leadconvert.setAccountId(accountId);

            }

            Leadconvert.setConvertedStatus(CLeadStatus.MasterLabel);

            Leadconvert.setDoNotCreateOpportunity(true);

            MassLeadconvert.add(Leadconvert);

        }

        if (!MassLeadconvert.isEmpty()) {

            List<Database.LeadConvertResult> lcr = Database.convertLead(MassLeadconvert);

        }

    }

    public class Requests {

        @InvocableVariable(label = 'LeadId' required = true)

        public Id LeadId;

        @InvocableVariable(label = 'AccountID')

        public String AccountId;

    }

}

以上でApexの設定は完了です

2 フローを作成しよう

フロー作成全体図はこちら
フロー1.png

開始条件は今回「評価」が「Hot」に設定

hot.png

アクションでAutoConvertLeads を選択
*LeadId は
{!$Record.Id}
に設定

アクション01.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?