Real, battle-tested AMPscript, SSJS, SQL, CloudPage and API snippets — used 41,925+ times by SFMC devs.
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>by SFMC Pilot
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", "
…by Community
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
…by SFMC Pilot
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 …
by Community
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 = 1by SFMC Pilot
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
…by Community
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}}",
…by SFMC Pilot
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
…by Community
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
…by SFMC Pilot
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
…by Community
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 …
by SFMC Pilot
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
…by Community