Messaging Made EasySending Messages

Sending a message using Apex

You can send messages from Apex using our Apex API. This API allows you to send messages using the Messente class which can be accessed through the gams4sf namespace as gams4sf.Messente. The following methods are available with example code provided at the end of the article.

sendSMSMessage(String phoneNumber, String message)

Sends a single SMS message to the provided number using the message text provided. Note the message is not stored.

Signature

global static String sendSMSMessage(String phoneNumber, String message)

Parameters

phoneNumber

Type: String

Description: The phone number you wish to send the message to in e.164 format

message

Type: String

Description: The message to send to the number.

Return Value

Type: String

Description: The unique omnimessage_id value for this message from Messente.

sendSMSMessages(List<String> phoneNumbers, String message)

Sends the same message to a set of phone numbers. Note that the message is not stored.

Signature

global static List<String> sendSMSMessages(List<String> phoneNumbers, String message)

Parameters

phoneNumbers

Type: List<String>

Description: The list of phone numbers you wish to send the message to in e.164 format

message

Type: String

Description: The message to send to the numbers.

Return Value

Type: List<String>

Description: The set of unique omnimessage_id values for these messages from Messente.

sendAndLogSMSMessage(SMS message)

This sends an SMS message to a number and records the sending of the message in the system as a gams4sf__Message__c record.

Signature

global static Id sendAndLogSMSMessage(SMS message)

Parameters

message

Type: SMS (custom Apex class, see below)

Description: A wrapper class instance that details the SMS message to be sent and recorded.

Return Value

Type: Id

Description: The Id of the gams4sf__Message__c record created for the sent message.

sendAndLogSMSMessages(List<SMS> messages)

This sends a series of SMS messages and records the messages in the system as gams4sf__Message__c records.

Signature

global static List<Id> sendAndLogSMSMessages(List<SMS> messages)

Parameters

message

Type: List<SMS> (custom Apex class, see below)

Description: A list of wrapper class instances that detail the SMS messages to be sent and recorded.

Return Value

Type: List<Id>

Description: The Ids of the gams4sf__Message__c records created for the sent messages.

sendViberMessage(String phoneNumber, String message)

Sends a single Viber message to the provided number using the message text provided. Note the message is not stored.

Signature

global static String sendViberMessage(String phoneNumber, String message)

Parameters

phoneNumber

Type: String

Description: The phone number you wish to send the message to in e.164 format

message

Type: String

Description: The message to send to the number.

Return Value

Type: String

Description: The unique omnimessage_id value for this message from Messente.

sendViberMessages(List<String> phoneNumbers, String message)

Sends the same message to a set of phone numbers. Note that the message is not stored.

Signature

global static List<String> sendViberMessages(List<String> phoneNumbers, String message)

Parameters

phoneNumbers

Type: List<String>

Description: The list of phone numbers you wish to send the message to in e.164 format

message

Type: String

Description: The message to send to the numbers.

Return Value

Type: List<String>

Description: The set of unique omnimessage_id values for these messages from Messente.

SMS Wrapper Class

The SMS wrapper class wraps the details necessary to send and record SMS messages as gams4sf__Message__c records.

Constructor Signature

SMS(String recipient, String message, Id recordId)

Parameters

recipient

Type: String

Description: The phone number to send the message to in e.164 format.

message

Type: String

Description: The message text to send to the recipient

recordId

Type: Id

Description: The Id of the record to relate the associated gams4sf__Message__c records to.

Example Code

1//Send a single SMS Message - not recorded
2String singleOmnimessageId = gams4sf.Messente.sendSMSMessage('+447700123456', 'Single message');
3
4//Send the same SMS message to multiple recipients - not recorded
5List<String> multiOmniMessageIds = gams4sf.Messente.sendSMSMessages(new List<String>{'+447700123456', '+447700123457'}, 'Multiple messages');
6
7//Send a single SMS message and have it recorded against a contact
8gams4sf.Messente.SMS message = new gams4sf.Messente.SMS('+447700123456', 'Single logged message', '003WS000002jumUYAQ');
9Id singleMessageId = gams4sf.Messente.sendAndLogSMSMessage(message);
10
11//Send multiple unique SMS messages at once and have them recorded against contacts
12List<gams4sf.Messente.SMS> messages = new List<gams4sf.Messente.SMS>{    
13    new gams4sf.Messente.SMS('+447700123456', 'Multiple logged messages 1', '003WS000002jumUYAQ'),    
14    new gams4sf.Messente.SMS('+447700123457', 'Multiple logged messages 2', '003WS000002jumUYAQ')};
15List<Id> multiMessageIds = gams4sf.Messente.sendAndLogSMSMessages(messages);