← SFMC PilotInterview Prep →
Community Templates

Copy-paste ready SFMC templates

Real, battle-tested AMPscript, SSJS, SQL, CloudPage and API snippets — used 41,925+ times by SFMC devs.

ampscript 4,820

Welcome Email with Personalization

Null-safe AMPscript welcome email with fallback greeting and dynamic firstName lookup.

%%[
  SET @email = AttributeValue("EmailAddress")
  SET @first = Lookup("Subscribers","FirstName","EmailAddress",@email)
  IF EMPTY(@first) THEN SET @first = "there" ENDIF
]%%
<p>Hi %%=v(@first)=%%,</p>
<p>Welcome aboard — we're glad you're here.</p>
#ampscript#personalization#welcome

by SFMC Pilot

json 3,105

Abandoned Cart Journey (JSON)

Journey Builder JSON export for a 3-step abandoned cart flow with decision splits and goal.

{
  "name": "Abandoned Cart",
  "entry": { "source": "DE:Cart_Events" },
  "activities": [
    { "type": "wait", "duration": "1h" },
    { "type": "email", "key": "cart_reminder_1" },
    { "type": "decision", "condition": "Purchased == true", "yes": "exit", "
…
#journey#cart#ecommerce

by Community

html 2,780

Preference Center CloudPage

Responsive CloudPage that reads subscriber via encrypted token and upserts preferences.

%%[
  SET @sk = RequestParameter("sk")
  SET @email = Lookup("Subscribers","EmailAddress","SubscriberKey",@sk)
  IF RequestParameter("submitted") == "1" THEN
    UpsertData("Subscriber_Preferences", 1,
      "EmailAddress", @email,
      "Frequency", RequestPa
…
#cloudpage#preferences#gdpr

by SFMC Pilot

sql 5,210

RFM Segmentation Query

Recency-Frequency-Monetary scoring against _Sent, _Open and an Orders DE. Ready to schedule.

SELECT
  s.SubscriberKey,
  NTILE(5) OVER (ORDER BY MAX(o.OrderDate) DESC) AS R,
  NTILE(5) OVER (ORDER BY COUNT(o.OrderID) DESC)  AS F,
  NTILE(5) OVER (ORDER BY SUM(o.Amount) DESC)     AS M
FROM Subscribers s
LEFT JOIN Orders o ON o.SubscriberKey = s.Subscri
…
#sql#segmentation#rfm

by Community

sql 6,740

Deduplicate DE by Email (SQL)

ROW_NUMBER pattern to keep the newest row per EmailAddress in a target DE.

SELECT SubscriberKey, EmailAddress, FirstName, LastName, ModifiedDate
FROM (
  SELECT *, ROW_NUMBER() OVER (
    PARTITION BY EmailAddress ORDER BY ModifiedDate DESC
  ) AS rn
  FROM Master_Subscribers
) t
WHERE t.rn = 1
#sql#dedup

by SFMC Pilot

ssjs 2,180

WSProxy Batch DE Update (SSJS)

10× faster batch update against a Data Extension using WSProxy — with error handling.

<script runat="server">
Platform.Load("Core","1.1.5");
try {
  var api = new Script.Util.WSProxy();
  var updates = [];
  for (var i = 0; i < rows.length; i++) {
    updates.push({
      CustomerKey: "Loyalty_Members",
      Properties: [
        { Name: "Emai
…
#ssjs#wsproxy#automation

by Community

json 3,980

Transactional Send (REST)

Fire a Triggered Send Definition via REST with dynamic recipient + attributes.

POST https://{{subdomain}}.rest.marketingcloudapis.com/messaging/v1/messageDefinitionSends/key:TS_WELCOME/send
Authorization: Bearer {{access_token}}
Content-Type: application/json

{
  "To": {
    "Address": "{{email}}",
    "SubscriberKey": "{{contactKey}}",
…
#api#rest#triggered-send

by SFMC Pilot

html 4,410

Dark-Mode Ready Email Boilerplate

Bulletproof table layout with @media prefers-color-scheme dark styles and Outlook fallbacks.

<!doctype html>
<html>
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width,initial-scale=1" />
  <style>
    @media (prefers-color-scheme: dark) {
      .bg { background:#0b0f1a !important; }
      .fg { color:#f4f6fb !importa
…
#html#email#dark-mode

by Community

sql 1,520

GDPR Right-to-be-Forgotten (SQL)

Cascade delete a ContactKey from non-sendable DEs. Pair with Contact Delete for sendable ones.

-- Run per non-sendable DE keyed on ContactKey
DELETE FROM Order_History     WHERE ContactKey = '{{contactKey}}';
DELETE FROM Preference_History WHERE ContactKey = '{{contactKey}}';
DELETE FROM Engagement_Facts   WHERE ContactKey = '{{contactKey}}';

-- Then l
…
#sql#gdpr#privacy

by SFMC Pilot

ampscript 3,320

Dynamic Product Recommendations

LOOKUPORDEREDROWS-driven product block with graceful fallback when no recommendations exist.

%%[
  SET @rows = LookupOrderedRows("Recommendations", 3, "Score desc", "SubscriberKey", _subscriberkey)
  SET @count = RowCount(@rows)
]%%
%%[ IF @count > 0 THEN ]%%
<table><tr>
%%[ FOR @i = 1 TO @count DO
     SET @row = Row(@rows, @i)
     SET @name = Field
…
#ampscript#personalization#recommendations

by Community

sql 990

Salesforce → SFMC DE Sync (SSJS)

Nightly sync from Sales Cloud via MCC Synchronized DE into a working DE with change tracking.

INSERT INTO Master_Contacts_Working
SELECT
  Id                                    AS ContactKey,
  Email                                 AS EmailAddress,
  FirstName, LastName,
  MailingCountry                        AS Country,
  HasOptedOutOfEmail,
  LastMo
…
#mcc#sync#sales-cloud

by SFMC Pilot

ampscript 2,870

One-Click Unsubscribe CloudPage

RFC 8058 compliant one-click unsubscribe endpoint with LogUnsubEvent + confirmation page.

%%[
  SET @sk    = RequestParameter("sk")
  SET @jobid = RequestParameter("jobid")
  SET @lid   = RequestParameter("listid")
  SET @batch = RequestParameter("batchid")
  IF NOT EMPTY(@sk) THEN
    LogUnsubEvent(@sk, @jobid, @lid, @batch)
  ENDIF
]%%
<h1>You're
…
#cloudpage#unsubscribe#compliance

by Community