How To Automate Salesforce Campaign Naming Conventions

Campaign naming conventions are a must have. They keep your campaigns organized, improve reporting, and provide key information about the campaign at a glance. However, campaign naming conventions can only be helpful if they are used — and used consistently. 

Enforcing naming conventions is tricky because it typically relies on the users to remember the order, abbreviations, variations by type etc. Without good governance, your campaigns will end up having disparities.

Here’s an example of possible disparities: 

Instead of continuing to rely on your users remembering your naming conventions, we can automate this process with APEX.

But First

Before you start automating your campaign names, ensure the data that goes into your naming conventions is on the campaign object. For instance, my naming convention is YYYY_MM_Campaign Type_Description/Name, so I’ll need to make sure the following fields are required:

  1. Start Date 

Year and Month will be pulled from this field

  1. Campaign Type 

Create a picklist field on the campaign object for your different campaign types such as webinar, email, trade show, etc.

  1. Short Name 

Create a text field on the campaign object for the user specified description/name. The user will only enter data into the “Short Name” field, the default field “Campaign Name” will be completed by our APEX trigger.

You’ll need to do a quick calculation to see how long your new Campaign “Short Name” field can be. The default “Campaign Name” field can only be 80 characters, so you’ll need to calculate:

calculating character count for naming convention


The Campaign “Short Name” field can be up to 58 characters.

To ensure this is clear to your users, add Help Text to both the “Short Name” and “Campaign Name” fields.

new campaign

Automating the Salesforce Campaign Name

Next, we’ve created a little Salesforce DX project that you can take a look at to see an example of how this can be done:

The project includes the Custom Field, Trigger code and the APEX Test code as well.

The CampaignNameTrigger is how we can enforce the Name of the Campaign. In this code, we see that we are using the date format “YYYY_MM_” to get us started, which will write out the 4 digit year and 2 digit month. Other formats are available.

trigger CampaignNameTrigger on Campaign (before insert, before update) {
    if(Trigger.isBefore && Trigger.isInsert) {
        //we will set the Name of the Campaign based on other fields,
        //overwriting whatever was placed there before
        for(Campaign campaign : {
            campaign.Name = 
                + campaign.Type + '_' + campaign.Short_Name__c;
            if(campaign.Name.length() > 80) //make sure length is good
                //if it isn't, trim it down to size
                campaign.Name = campaign.Name.substring(0, 80); 
    else if(Trigger.isBefore && Trigger.isUpdate) {
        for(Campaign campaign : {
            Campaign oldCampaign = Trigger.oldMap.get(campaign.Id);
            //first lets see if anyone else tried changing the name
            if(campaign.Name != oldCampaign.Name) {
                //we want to prevent that
                campaign.addError('You can\'t change the Name directly.');
            //ok, we are safe to set the correct value now
            campaign.Name = 
            + campaign.Type + '_' + campaign.Short_Name__c;
            if(campaign.Name.length() > 80) //make sure length is good
                //if it isn't, trim it down to size
                campaign.Name = campaign.Name.substring(0, 80); 

This trigger will also trim the final campaign name down to 80 characters, if needed. 

Once implemented, the above APEX Trigger will fire whenever a Campaign is created and/or edited. 

final view

This is a subtle reminder that this year’s ParDreamin virtual conference starts on October 27th! Register here.

Want to automate your campaigns even further? Check out how you can auto-generate and enforce campaign member statuses by campaign type.

Thanks to Adam Erstelle for contributing to this post.

The post How To Automate Salesforce Campaign Naming Conventions appeared first on The Spot For Pardot.

By |2021-09-21T15:09:57+00:00September 21st, 2021|Categories: Campaigns, Data Management, Salesforce|

Pardot Protected Campaign Member Statuses Solution

Get a solution for Protected Campaign Member Statuses in Pardot and step-by-step instructions for installation.

We go through all the effort of setting up beautiful Salesforce Campaigns, naming standards and maybe even a hierarchy. The next challenge in completing your beautiful work of campaign art is getting a hold on your Campaign Member Statuses for each campaign.

When a new Salesforce Campaign is created, many people aren’t just happy with the two default statuses of Sent and Responded. This prompts them to create what they think makes the most sense. Though as time goes on and as reporting starts to be needed, everyone making their own Campaign Member Statuses can be a nightmare that prevents you from getting meaningful and actionable intelligence. It would be really nice to take the guesswork out of status reporting and have a standard set of Campaign Member Statuses everyone uses consistently.

Jenna Molby posted a fantastic solution that enables you to automatically create the right Statuses on Campaign creation.

The automation here is good, though as you increase the number of Types the Flow could become a bit unwieldy.

Another thing that could be a problem comes later when other people might make changes to your carefully crafted structure. What happens if someone edits or even removes these statuses?

Install Protected Campaign Member Statuses

Protected Campaign Member Statuses is a free solution you can install and easily configure to solve this problem. It allows you to:

  1. Define the Campaign Member Statuses that should always be present on given Campaign Types.
  2. Restore the Protected Statuses on Active Campaigns should someone make changes.
  3. Create additional Statuses for specific reasons.
  4. Override by authorized users on a per-Campaign basis.

I don’t want the details, just let me install it

(Don’t worry. Keep reading to learn exactly what’s going on inside.)

We have an Unlocked Package you can install that sets up the application.

Get Started

Once installed, you need to define your Protected Statuses. This is done with Custom Metadata Types.

  1. Login to Salesforce Lightning, and go to Setup.
  2. Navigate to Custom Metadata Types, and click Manage Records for Protected Campaign Status.
    Pardot Protected Campaign Member Statuses
  3. To create your first ones, click New
    Pardot Protected Campaign Member Statuses
  4. Fill in the various fields.
    • Label: Used in the List of Campaign Statuses in the Setup view in step 3 above. Recommended convention:  TYPE-STATUS
    • Name: This is an API name that can be used by developers. Not required by this package. Recommended: let this autofill after you type in the Label.
    • Campaign Type: This is the actual value for the Campaign’s Type field.
    • Protected Status: This is the Status value that will become protected.
    • Is Default: Select this if this Status should be the default (please pick only 1 per Type).
    • Is Responded: Select this if this Status should be marked as Responded.
    • When complete, your screen may look something like this:
      Pardot Protected Campaign Member Statuses
  5. Click Save (or Save & New) and repeat a whole bunch.
  6. Lastly, time to set up a scheduled job to restore deleted protected statuses.
  7. Back in Setup, go to Apex Classes and click Schedule Apex.
    Pardot Protected Campaign Member Statuses
  8. Fill in the few fields.
    • Job Name: give this a nice descriptive name so you remember what it is in 3 months.
    • Apex Class: SL_ProtectedCampaignStatusJob
    • Frequency: set this to what works for you. We recommend running this daily during off-peak hours.
    • Start: today
    • End: some time in the distant future
    • Preferred Start Time: off peak hours
    • When complete, your screen may look something like this:
      Pardot Protected Campaign Member Statuses

You are good to go once you have provided your statuses. Give it a whirl by creating a new Campaign with the Type you have set up. Then take a look at the statuses already created.

Campaigns with Types not already set up will keep the default two statuses that Salesforce creates.

That’s cool. What’s behind the curtain?

To accomplish this, we leverage a few cool tools available to us:

  • Custom Metadata Types: Allows the Protected Statuses to be treated like normal Salesforce metadata and can be deployed around like any other metadata (changesets, insert devops tool here)
  • Campaign Custom Field: Has_Protected_Campaign_Member_Statuses__c is automatically checked by the solution if a Campaign is created and there are Custom Metadata Type records that specify this Campaign’s Type. It is also what allows the rest of the code to keep the statuses intact. You can clear the checkbox for this field to make changes to the statuses if you need to. However, you can’t enable protection afterwards.
  • Change Data Capture: We turn this on for CampaignMemberStatus so we can detect edits to statuses and then fix the records after-the-fact. Sadly we can’t (yet?) put any triggers on CampaignMemberStatus (which would have been ideal).
  • Triggers: yea these have been around for a while and are quite handy. We use them to kick off the automation that we’ve built when a Campaign is created. We also use them to watch for Campaign Member Status edits (through the ChangeEvents from Change Data Capture) so we can set things right afterwardsd.

If you want even more details, check out the Github project where you can see all the inner workings of what is going on.

Further Reading

Here are some resources you can use to learn more about Salesforce Campaigns and how they work in Pardot:

The post Pardot Protected Campaign Member Statuses Solution appeared first on The Spot For Pardot.

By |2021-07-16T18:27:52+00:00July 16th, 2021|Categories: Campaigns, Data Management|