Use the SMS integration feature

Updated at:

Send SMS messages using the CXG SMS component

Prerequisites

  • Complete the SMS connector configuration.

  • Complete the SMS signature and template configuration.

  • Complete the CXG SMS component configuration.

Introduction

On the configured SMS component interface, select a recipient from a `Phone` field. Select a configured signature and template. Enter the values for any parameters that the template cannot automatically retrieve. Click Send to send the SMS message.

Using templates

If a template contains SMS variables:
1. Salesforce variables
When you select an associated object, the corresponding Salesforce variable reads its value from that object. If the field is empty, you must enter the value manually.
2. Manually entered values
If a template contains variables that are not from Salesforce, or if a field in an associated object is empty, you must enter the variable values manually before you send the message.



Send SMS messages by calling an Apex class

Prerequisites

  • Complete the SMS connector configuration.

  • Complete the SMS signature and template configuration.

Introduction

Note

CXG provides an Apex class that you can call directly to send SMS messages. For more information about Apex classes, see Apex Developer Guide | Salesforce Developers. This section uses a Flow Action as an example to show how to use this class in a CRM. The example demonstrates how to configure the Salesforce interface to add an action that sends an SMS message.

SMS Apex class parameters

  • `String phone`: The recipient's mobile phone number.

  • `String objectName`: The name of the associated object. This parameter is used only when `createTask` is set to `true`.

  • `String recordId`: The ID of the associated object record. This parameter is used only when `createTask` is set to `true`.

  • `String templateId`: The ID of the `CXG__SmsTemplate__c` object in Salesforce.

  • `String signId`: The ID of the `CXG__SmsSign__c` object in Salesforce.

  • `List<CXG.ExternalSmsTemplateParam> templateParams`: This parameter is required if the template contains variables. If there are no template variables, pass `Null`.

  • `Boolean createTask`: Specifies whether to create a Task object as a sending record after the message is sent.

CXG.ExternalSmsClient.send(String phone, String objectName, String recordId, String signId, String templateId, List<CXG.ExternalSmsTemplateParam> templateParams, Boolean createTask);
If you do not want a Task record to be automatically created after an SMS message is sent, set `createTask` to `false`. You can then pass null values for `objectName` and `recordId`. If a Task must be automatically created, you must grant the integration user the `Edit Tasks` permission.

Return parameter

  • CXG.ExternalSmsSendResponse

    • `String bizId`: The business ID that is returned by Alibaba Cloud after the SMS message is sent. You can use this ID to query sending records.

Step 1: Declare variables

Create a custom Apex class for passing parameters as shown in the following example. Each property must have the @InvocableVariable annotation, which is used in `@InvocableMethod` methods, and the @AuraEnabled annotation, which is used when you declare an Apex-defined type variable in a flow.

Example

public with sharing class SendSmsRequest {
 @InvocableVariable
 @AuraEnabled
 public String templateParam;
 @InvocableVariable
 @AuraEnabled
 public String phone;
}

Step 2: Create a Flow Apex class

Create an Apex class that can be called in a flow using the `@InvocableMethod` annotation. Example

public with sharing class SendSmsAction {
 @InvocableMethod
 public static void send(List<SendSmsRequest> params) {
 SendSmsRequest request = params.get(0);
 List<Namespace.ExternalSmsTemplateParam> templateParams = new List<Namespace.ExternalSmsTemplateParam>();
 templateParams.add(new CXG.ExternalSmsTemplateParam('Template Variable 1', request.templateParam_1));
 templateParams.add(new CXG.ExternalSmsTemplateParam('Template Variable 2', request.templateParam_2));
 CXG_TEST.ExternalSmsClient.send(request.phone, null, null, request.signId, request.templateId, templateParams, false);
 }
}

Step 3: Create a record-triggered flow

  • When you create a record-triggered flow, select Include a Run Asynchronously path for the Optimize the Flow for option.

  • In the Run Asynchronously path, create an action. Search for the class that you created in Step 2, such as the `SendSmsAction` class in the example.

  • In the Set Input Values for the Selected Action section, enable the `Include` toggle and select the required variables.

  • Click Save and activate the flow. Then, verify that the flow runs as expected.