Skip to content

使用 Apex 发送短信

可以通过 SmsManager 类来发送验证码短信,通知短信和营销短信。

sendVerificationCode

发送指定的验证码

// phoneNumber: The phone number of the verification code recipient.
// templateId: The ID of the SMS template.
// signatureId: Required if using a signature, optional otherwise. The ID of the SMS signature.
// verificationCode: The specified verification code to send.
// whoId: The identifier of an object in the database, typically a contact or lead. It is used to associate the SMS message record.

CharketApp.SmsSendVerificationCodeResult result = CharketApp.SmsManager.sendVerificationCode(phoneNumber, templateId, signatureId, verificationCode, whoId);

 

sendVerificationCode

发送指定长度的验证码

// phoneNumber: The phone number of the verification code recipient.
// templateId: The ID of the SMS template.
// signatureId: Required if using a signature, optional otherwise. The ID of the SMS signature.
// verificationCodeLength: The specified verification code length to generate and send code.
// whoId: The identifier of an object in the database, typically a contact or lead. It is used to associate the SMS message record.

CharketApp.SmsSendVerificationCodeResult result = CharketApp.SmsManager.sendVerificationCode(phoneNumber, templateId, signatureId, verificationCodeLength, whoId);

verifyCode

验证指定的验证码

// smsMessageId: The ID of the SMS message.
// code: The verification code to be verified correct.

Boolean result = CharketApp.SmsManager.verifyCode(smsMessageId, code);

在升级到 v1.3 后Process Builder 不支持发送 NotificationMarketing Message 类型的短信,可以使用 Flow 或 Apex 来发送。

注:

  • v1.3.0 之前的版本配置的 Process Builder 在升级到 v1.3.0 后仍然可以工作。
  • 如果使用 Screen Flow 批量发送短信,则建议发送消息数量在 20 条左右,否则数据太多,会出现超时的情况

sendMessages(List<SmsMessage> smsMessages)

同步发送 SMS 消息。 SmsMessage List 的 size 最大为 10。每个 SmsMessage 中 recipients 的数量最多限制是 200 个。

global static List<SmsSendMessagesResult> sendMessages(List<SmsMessage> smsMessages)

 

asyncSendMessages(smsMessages)

异步发送 SMS 消息。 每个 SmsMessage 中 recipients 的数量最多限制是 200 个。

global static Void asyncSendMessages(List<SmsMessage> smsMessages)

 

Charket
扫码获得帮助