I have provided two pieces of code, one for SMS Template and the other for SMS History. This piece of code will add a disclaimer type of message under each message you send from Salesforce.

To add the triggers, please follow the below given steps - 

  1. Go to Setup(top right corner) 
  2. On the left panel search for App Setup - Create - Objects
  3. Click on Objects
  4. Open SMS Template and SMS History in two different tabs
  5. Scroll down to Triggers in each tab
  6. Click on the New button
  7. Make sure that the Apex Trigger textbox is blank for both SMS Template and SMS History
  8. Add the triggers as shared below in their respective objects.

You can refer the below code - 

for SMS Template

trigger AddDisclaimerTemplateTrigger on smagicinteract__SMS_Template__c (before insert, before update) {
    for(smagicinteract__SMS_Template__c templateObj : Trigger.new) {
            && !templateObj.smagicinteract__Text__c.containsIgnoreCase('Text STOP to Opt Out')) {

            templateObj.smagicinteract__Text__c = templateObj.smagicinteract__Text__c + '\r\nText STOP to Opt Out';


for SMS History

trigger AddDisclaimerSMSTrigger on smagicinteract__smsMagic__c (before insert) {
    for(smagicinteract__smsMagic__c smsobj : Trigger.new) {
        if(smsobj.smagicinteract__disableSMSOnTrigger__c != 1
            && String.isNotBlank(smsobj.smagicinteract__SMSText__c) 
            && !smsobj.smagicinteract__SMSText__c.containsIgnoreCase('Text STOP to Opt Out')) {

            smsobj.smagicinteract__SMSText__c = smsobj.smagicinteract__SMSText__c + '\r\nText STOP to Opt Out';

The highlighted portion in each trigger is the part where you can add your own disclaimer message.

Once you have created the triggers, the trigger names would be "AddDisclaimerTemplateTrigger" on SMS History and "AddDisclaimerTemplateTrigger" on SMS Template.

Limitations - 

  1. For single and bulk sms, the disclaimer will be added if there was no disclaimer added previously.
  2. If the disclaimer is already there in the sms, there will be no duplication.
  3. The duplication will not be there provided the disclaimer is in the correct format as you may have defined in the trigger according to your requirement.
  4. For campaigns, workflows and schedulers - the templates which you would use while sending text messages, they need to be edited(small tweak, for eg. adding a space and deleting it once again) and then you will see the disclaimer added in the template.
  5. If you have many templates which need to edited, you can use the Data Loader or write an update query on the SMS templates from the Developer Console.
  6. While sending messages using campaigns, workflows or schedulers, at the time of final rendering the template in the text box, if the disclaimer is removed manually by a User, the disclaimer won't auto-populate.(as it does for the single sms and bulk sms)