Desktop Banner Mobile Banner

How to Send Messages from Apex

Author
Siddharth Sehgal

19 Jan 2022

Listen to this article

Send messages from Apex

Automation has paved several ways to accelerate business operations. And one of the crucial instances of automation in business is text automation. Automated texts have enabled employees to send texts at a defined time for meaningful interaction without being rigorously involved in text operations. This further helps employees to save time and focus on core business priorities. For automation, Salesforce offers various tools like Process Builder, Flows, Workflows, etc. Users can also send messages from Apex to automate text messages through coding.

What is Apex?

Apex stands for Advanced Programming Experience in Salesforce. It is an object-oriented programming language developed by salesforce.com. It allows developers to write code that works on the force.com platform and create SAAS applications accessing client-server interfaces and Salesforce.com’s back-end database. 

Besides, developers can make API calls to Flow.com and execute flow and transaction control statements using Apex. Users can initiate Apex Code from triggers on objects and Web service requests.

When to use and Send Messages from Apex

Users can automate and send messages using a process builder. Also, Flow builder is one of the Salesforce automation tools that help to automate a guided visual experience and start a behind-the-scenes business process. But, users can count on Apex when they need more capabilities than what is provided by Flow Builder. They can use Apex to accommodate more complex automation use-cases.

How to Send Messages from Apex

Apex class can be executed in Process Builder, Flows, or trigger code.

Certain parameters need to be defined to send messages using Apex.

The Apex classes accept parameters in a comma-separated string.

 

  • Select action name as send SMS APEX

 

  • Select Apex class as send SMS from Process Builder

 

  • Set Apex variable and define parameters.

 

Param1: Add the Id of the primary object from which you are triggering the message. This should match your template object. Also, the outbound SMS will relate to this Salesforce primary object only. 

Param2: The API name of the phone field for that object or an actual valid phone number.

Param3: This parameter can be any one of the three-  

  • An SMS template Id, or
  • A question Id, or
  • A string

Template Id: 

You can extract a Template Id from the URL of an SMS template. Its object should match the Salesforce object defined in Param1. 

Question Id: 

Add a question Id of the first Survey question, which you want to trigger. After triggering the Survey’s first question, all responses will be handled automatically. 

String (Straight Text): 

You can add a string in this parameter if you do not want to use templates. This works well for simple text messages. The string also supports ‘Merge tags’. For example, Okay {Contact.firstname}. This is a message template.

Param4: Add an outbound phone number that you want to use to send an outbound text. It will pick the default phone number for the org or the first phone number mentioned in the 360 SMS user configuration tables if Param4 is blank.

After defining parameters, you are all set to automate messages.

Pick the Best-Suited Tool and Minimize Effort

Though there are different tools available in Salesforce to automate text messages, every tool has its own importance and unique capabilities. With adequate knowledge of tools like Process Builder, Apex code, etc., business ventures can use the appropriate method to automate and send text messages. This helps them pick the best-suited tool, minimize team effort and perform text operations at a much faster rate.

To know more about no-code and standard automation in Salesforce, turn to our experts at sales@360smsapp.com or contact us here.

Recent Blogs

Send Bulk SMS & Text Messages from Salesforce: The Complete Guide
Advanced Messaging Platforms 22 Jan 2026
Send Bulk SMS & Text Messages from Salesforce: The Complete Guide

Listen to this article If you’ve ever tried reaching hundreds—or thousands—of customers one message at a time, you already know…

Author
Siddharth Sehgal
Read More icon
WeChat Integration for Messaging: Common Pitfalls and Solutions
SMS App 16 Jan 2026
WeChat Integration for Messaging: Common Pitfalls and Solutions

Listen to this article WeChat is one of the most popular social media channels for global messaging, with an extremely…

Author
Raveena Raghav
Author
Read More icon
What Is a Salesforce Chatbot? The Secret Tool Boosting Sales by 300%
Chatbot in Salesforce 09 Jan 2026
What Is a Salesforce Chatbot? The Secret Tool Boosting Sales by 300%

Listen to this article Over the past decade, sales teams have seen an explosion of automation tools, but few innovations…

Author
Raveena Raghav
Author
Read More icon

Contact Us

No matter where you are from, we provide Global Coverage.

Please select country below

By clicking 'Submit,' I agree to subscribe to promotional messages and newsletters.

captcha

Refresh icon