Avo4SF MCO - Messages Custom Object Package

Add-on package to Avo4SF that allows for created scheduled messages in Salesforce

The MCO package is an unlocked package that works as an add-on to your Avochato for Salesforce package, and can enhance the way you can schedule Avochato messages from your Salesforce org.

Note that you must have the main Avochato for Salesforce package installed in order to install the MCO package into your Salesforce org.

This article walks you through this unlocked package, why it exists, and some of the components and functionality packed inside.

Package Overview

What is MCO package?

The Messaging Custom Object package allows you the create custom Message records that can be sent in the future. The package includes a scheduled job that runs every hour, scanning for any scheduled messages, and sending out those messages when the appropriate date and time (accurate to the hour) arrives.

How to Use (and Why)

You can create these Avochato Message records manually or through Salesforce automation. The most common use case is the use Salesforce Flow Builder to create Avochato Messages based on changes to Salesforce record data, so you can schedule a text message to the right phone number at the appropriate datetime.

Anytime Avochato messages are being sent en mass via Salesforce automation (like Flow builder), Salesforce limits are easily hit and prevent the messages from being sent.

The Avochato Message custom object fills this gap, where you can create Avochato Messages en mass through Salesforce Flow builder, and then the actual Avochato API callouts can be made at the closest relevant hour, and avoiding triggered/real time Salesforce limits.

Avochato Message custom object

MCO is a special add-on package that installs a few new components to your Salesforce org, including the Avochato Message custom object with the following fields:

Field API Name
Message Name
string (80), auto number
Auto-named, formatted MSG-{0000000}
Owner ID
User responsible for creating the message
textarea (3000), required
The message to be sent
Scheduled Send Date
datetime, required
The date and hour that the message will be sent
picklist (255)
Status of this message record. Possible Values: Scheduled, Sent, Sent - Async, Attempted - Error Default status is Scheduled
string (80)
The Avochato Inbox/Account to sent this message on behalf of
string (255)
Avochato tags to associated with this message
To Phone
phone (40), required
The destination phone that will receive this message
Error Message
textarea (3000)
If a realtime message is sent, if there is an issue with the API callout, the error message is recorded here.
Associated Record Id
string (18)
The record Id in Salesforce that’s associated with this message
Lookup (Contact)
Lookup field to the contact that’s associated with this message
Lookup (Lead)
Lookup field to the lead that’s associated with this message

AvochatoMessagesJob - Apex Batchable and Scheduleable Job

Avochato Message records can be created by any means that make sense for your Salesforce org. In the background, we run an hourly scheduled job that scans for Avochato Message records that are scheduled to be sent within the current hour, and have been set to the “Scheduled” status. All those records will have their Message sent to the To Phone specified on the record.

How to: Scheduling the default AvochatoMessagesJob to run every hour

// Runs the default scheduled job, setting the batch size to `1`
// and sends messages asychonously using the Queueable technology

After scheduling the job, it should run every hour and send the messages it finds within that hour slot and in the “Scheduled” status.

Go into your Setup → Scheduled Jobs section to confirm that the “Avochato Messages Job” is in that list. You’ll be able to see when the job was created and when is the next time it is scheduled to run.

Want to try running it one time for the current hour time slot? Try some of the options below:

How to: Running an AvochatoMessagesJob one-time async batch job

AvochatoMessagesJob msgJob = new AvochatoMessagesJob(1);
Database.executeBatch(msgJob, 1);

How to: Run Larger batch sizes in realtime (i.e. not using Queueable or @future technology)

// Up to 50 synchronous API callouts can be made according to SF limits
//   - We suggest using 10 or less, as your SF org may have other automation
//     that may consume some of these resources and limits.
//   - Synchronous API callouts populate the Avochato_Message__c.Error_Message__c
//     when an unexpected error has accorded, which can be invaluable when 
//     debugging edge cases
AvochatoMessagesJob msgJob = new AvochatoMessagesJob(10, false);
Database.executeBatch(msgJob, 10);

How to Install

Install the Package

Use the following link to install the latest MCO unlocked package.

When prompted for the password, use the password your Avochato Account manager gave you for the MCO package.

Note: Select the “Install for All Users” option, as well as within the Advanced Options → “Compile only the Apex in the package” option. That will ensure the unit tests pass and that the package installs in a timely manner.
Notion image

Post Install Permissions (Required)

Once the MCO package is installed, there’s a few permissions that need to be adjusted to expose the new Avochato Message custom object to your Salesforce automation and users.

Although you can configure these permissions with your own Profile or Permission Set adjustments, we suggest making the following adjustments:

  • Go into the Avochato Connected App User permission set, click into Object Settings → Avochato Messages
    • Edit the permissions that you would like all your Avo4SF users to have. Here’s a sample of those permissions (you can also mark Delete true if you’d like users to be able to delete these scheduled Avochato Message records as well). Click Save.
      • Notion image
    • Back into the Permission Set Overview, click into Apex Class Access, and ensure this permission set has access to AvochatoMessagesJob
      • Notion image

Page Layout adjustments

If you’re using the Contact or Lead lookup fields on the Avochato Message records, edit the active Page Layout associated with the Contact/Lead and add the “Avochato Messages” Related List. That will show the relevant scheduled Avochato Messages that have been created to be sent towards that particular contact or lead.

Optional Avochato Message Field

There’s a few fields that you can use to enhance your message sending, or better keep track of message associations to SF records.

It is very worthwhile to set one of the Lead / Contact / Associated Record Id fields within Flow builder or however else you create the Avochato Message record, so that it’ll be associated to the right records for future reference and reporting purposes
Notion image
  • Subdomain: If you have multiple Avochato Inboxes, you can populate the Avochato Account subdomain to send a message on behalf of the specified inbox. If left blank, it’ll use the default Avochato Inbox associated with the default Avochato API Credentials saved in Salesforce (i.e the Custom Metadata Type Avochato Credential with the Default checkbox marked true)
  • Tags: You can associated tags to the Avochato messages being sent, so that you can organize and keep track of the different kinds of messages you’ve sent to your Avochato Contacts
  • Contact: When creating the Avochato Message, populate the Contact lookup field if there’s a particular SF Contact record that this message is associated with (like the matching contact’s phone number)
  • Lead: If you use Leads, associate the lead to this Avochato Message. You’ll be able to see all the Avochato Messages scheduled and sent within the Avochato Message related list
  • Associated Record Id: If you’re using a custom object, or just want to have a standardized field to save the record Ids, populate this to point to the SF record of choice.

Important Fine Print

Some important notes about this package:

  • This is an unlocked package that’s not officially on the AppExchange. It has not passed an official Security Review - the installer uses it at their own risk
    • With that being said, we always follow secure programming practices
  • Being an unlocked package means that the installing SFDC org can see the code and make modifications as if the installing org created it themselves.
    • This gives you flexibility to make additional tweaks and enhancements that suit your specific SF org and use cases
    • If you’ve made custom changes to the package on your org, newer versions of the MCO package will overwrite those changes.
      • Only install a newer version of the MCO package if you haven’t made any modifications to the existing components of the MCO package (or are 100% comfortable with any updates that might delete those custom modifications)
Did this answer your question?