Skip to main content
Build the future with Agentforce at TDX in San Francisco or on Salesforce+ on March 5–6. Register now.

Personalize a Birthday Email

Learning Objectives

After completing this unit, you’ll be able to:

  • Identify string functions.
  • Set variables in an email.

Basics Covered

Now that you have a refresher on AMPscript basics, let's move on to a few more concepts that can help you solve common AMPscript use cases. Let's start with strings. 

What Are Strings?

/* No, not silly string.*/ Functions can refer to values in a data extension, or they can use other constant values and even strings. A string is a set of one or more letters, numbers, spaces, or special characters surrounded by a delimiter, in this case a double (") or single (') quote. 

Here are a few examples that work:

'String text goes here'


"String text goes here"


"My string's inside quotes!"

And one example that doesn’t:

'Check out the world's best module!' 

This confuses the system and it would just read 'Check out the world' because the possessive quote is read as a delimiting quote. 

Note

AMPscript code only accepts straight quotes. Word processing apps often replace straight quotes with smart or curly quotes, so be careful when you copy and paste.

Use String Functions

You may come across situations where you need to manipulate string values to achieve different things. We can do this by using string functions. Click on the name of each function to see how to use it and example code.

AMPscript often requires the use of multiple string functions, so it’s helpful to know how these work separately before combining them.

Solve Marketing Challenges with AMPscript

Now that you’ve reviewed the basic syntax, some common functions, and even string functions, we want to get you up and running with some practical use cases. Over the next few units, we follow our favorite outdoor gear and apparel retailer Northern Trail Outfitters (NTO) as its technical marketer, Michele Hansley, solves some common email challenges using AMPscript to personalize emails. Each use case gets progressively more complex and uses a variety of AMPscript skills. 

Solution

Description

1: Personalize a birthday email.

NTO’s birthday email needs to be updated to include a static promotion, expiration date, and subscriber details based on information found in NTO’s main customer data extension. In addition, Michele needs to make sure the customer’s information is properly formatted and “NTO Rockstar” is displayed if a customer’s name isn’t available. 

2: Create a loyalty email.

NTO marketing manager, Isabelle Givens, wants to create a status email that shows a subscriber’s current award points and how close they’re to reaching a new reward.

3: Create a premium reward email. 

Isabelle also wants to provide a special coupon for premium customers to encourage more sales. The graphics team has created a special banner with a promo code to share with premium customers. The rest of the email remains the same. 

4: Create a data-driven email. 

Isabelle wants to create a new monthly email campaign for loyalty members that promotes new products based on the subscriber’s interests.

Solution 1: Personalize a Birthday Email

Let’s start with Michele’s first task. As mentioned, NTO’s birthday email needs to be updated. Here are the content and requirements Michele has been given.

Email Content:

Happy Birthday, FIRST NAME!

To celebrate your birthday on BIRTHDATE, we’re giving you 30% OFF your next order.

Hurry! This offer expires on EXPIRATION DATE. Use Promo Code: BDAY22 when you check out. 

Requirements:

  • Display NTO Rockstar if a customer’s first name is null.
  • Show the expiration date of 12/31/2024.
  • Use the Empty function to achieve this task.
  • Use variables from the NTO Customer data extension with field names:
    • First-Name
    • DOB

Here’s how Michele sets up the solution.

Set Variables

A core concept of AMPscript is declaring and setting variables. While we covered this in the prework, here’s a quick overview of Michele’s steps.

  1. Michele creates her code block and declares the variables.
  2. She adds in the variables from the data extension using SET @firstName = [First-Name] and SET @birthDate = [DOB]
  3. After that, she sets the constant variables not included in a data extension: SET @promoAmt = 30

Add Conditions

Next up, Michele needs to add in code to establish “NTO Rockstar” as a greeting, if a person’s first name is unavailable.

  1. Using a conditional IF statement, Michele sets the name to be NTO Rockstar if a customer’s first name is null. IF Empty (@firstName) THEN SET @firstName = "NTO Rockstar" ENDIF

Add Formatting

Finally, to ensure good, clean data, Michele wants to add formatting so both the customer’s first name and date of birth appear correctly in the email. 

  1. Michele uses the Proper Case function for the customer’s first name. %%=ProperCase(@firstName)=%%
  2. For the customer’s birthday, she adds in a date formatting function to ensure the birthday appears as Month Day. %%=FormatDate(@birthDate, "MMM DD")=%%

Example Code

%%[
/* Get data from sending DE and set as variables */
VAR @firstName, @birthDate
SET @firstName = [First-Name]
IF Empty(@firstName) THEN SET @firstName = "NTO Rockstar" ENDIF
SET @birthDate = [DOB]
/* SET promotional variables */SET @promoAmt = 30SET @expDate = "12/31/2024"]%%
Happy Birthday, %%=ProperCase(@firstName)=%%!
To celebrate your birthday on %%=FormatDate(@birthDate, "MMM DD")=%%, we’re giving you %%=(@promoAmt)=%% percent OFF your next order.
Hurry! This offer expires on %%=v(@expDate)=%%.

AMPscript is flexible, so there are many ways to do the same thing. Can you think of other ways to code this email? We can’t wait to see what you come up with.

Next Up: Create a Loyalty Email

Feeling accomplished? Great! Now you’re ready to focus on the next solution: creating a loyalty email. 

Resources

Salesforce ヘルプで Trailhead のフィードバックを共有してください。

Trailhead についての感想をお聞かせください。[Salesforce ヘルプ] サイトから新しいフィードバックフォームにいつでもアクセスできるようになりました。

詳細はこちら フィードバックの共有に進む