ServicesSalesforce consultingArchitectureImplementationOrg health checkDevelopmentIntegrations and APIsData migrationTesting and QAManaged supportSpecialist supportMarketing Cloud auditDeliverability
SolutionsMarketing Cloud EngagementMarketing Cloud NextSalesforce + BrazeAccount EngagementData Cloud (Data 360)Identity resolutionInsights and segmentsAgentforce and AIMCP integrationsSales and Service CloudReal-time personalisationIntegration solutionsEnterprise AI integrationBy industry
ArchitectureSalesforce CRMData 360Salesforce + BrazeAgentforceCustomer 360API-led integrationEvent-drivenMCP host, client and serverIdentity and consentMCP securityData governanceCI/CD and releasesOur public MCP server
ResourcesEngineering journalDecision guidesSolution blueprintsSalesforce productsProjects and achievementsSales ROI calculatorWhere we workChecklists and templatesPlanning toolsReadiness assessmentGlossaryAbout GeekMidstOur approachOur expertiseContact
CompanyAbout GeekMidstOur approachDelivery methodologyTrust and evidenceProjectsAchievementsBook a consultationContactWhere we workSecurity and data
Book a Consultation

AMPscript development

Personalised emails, SMS and CloudPages built with AMPscript that handles missing data gracefully and is readable by the next developer.

Developer compares two phones showing slightly different email layouts in front of a monitor of blurred code

AMPscript is the scripting language that turns a Marketing Cloud Engagement email into a personalised one. It reads subscriber attributes, looks up rows in data extensions, builds conditional content and powers CloudPages such as preference centres. It is also unforgiving: a lookup that returns nothing, a date in an unexpected format or a null value in a function call can stop a send or render a broken message.

An experienced AMPscript developer writes code that expects imperfect data, stays readable and is tested against the real shapes of your data extensions.

What we build

  • Dynamic email content driven by profile attributes, order history or product recommendations stored in data extensions.
  • Conditional blocks for language, region, loyalty tier or lifecycle stage.
  • CloudPages for preference centres, unsubscribe flows and simple forms that write back to data extensions.
  • SMS and push message personalisation using the same data.
  • Refactors of existing scripts that have grown long, slow or fragile.
Email builder where a content block is dragged from a block palette into a modular email layout, with a mobile preview showing the same email

An example of defensive AMPscript

The snippet below greets a subscriber by first name with a fallback, then reads their most recent order from a sample data extension. It assumes a data extension called Orders_DE with fields SubscriberKey, OrderNumber and OrderDate. It is a teaching example, not drop-in production code.

ampscript
%%[
SET @firstName = AttributeValue("FirstName")
IF EMPTY(@firstName) THEN
  SET @firstName = "there"
ENDIF

SET @rows = LookupOrderedRows("Orders_DE", 1, "OrderDate DESC", "SubscriberKey", _subscriberkey)
IF RowCount(@rows) > 0 THEN
  SET @row = Row(@rows, 1)
  SET @orderNumber = Field(@row, "OrderNumber")
  SET @hasOrder = "true"
ELSE
  SET @hasOrder = "false"
ENDIF
]%%
Hi %%=v(@firstName)=%%,
%%[ IF @hasOrder == "true" THEN ]%%
Thanks for order %%=v(@orderNumber)=%%.
%%[ ELSE ]%%
Here is what is new this month.
%%[ ENDIF ]%%
Fallback for a missing first name and a guarded lookup of the latest order

Two habits matter here. AttributeValue returns an empty value instead of erroring when the attribute is missing, and the RowCount check prevents Row() being called on an empty rowset. For a fuller comparison of lookup functions, see AMPscript LookupRows vs LookupOrderedRows. When something breaks in a live send, How to Debug AMPscript Personalization Errors walks through the diagnosis, and the AMPscript Cheat Sheet keeps common functions to hand.

Problems we are often asked to fix

  • Sends that error for some subscribers. Usually a lookup or date function receiving an empty or badly formatted value. We reproduce it with the affected records and add guards.
  • Slow sends. Several lookups per subscriber across large data extensions add up. Moving the joins into SQL before the send often helps more than tuning the script.
  • Copy-and-paste sprawl. The same logic repeated in dozens of emails, each slightly different. We consolidate it into shared content blocks so a fix happens once.
  • Previews that look fine but live sends that do not. Preview subscribers often have complete data. Testing against deliberately incomplete records catches the difference.

How we deliver AMPscript work

  1. 01

    Understand the data

    We review the data extensions, field types and fill rates behind each personalisation rule, because most AMPscript bugs are really data problems.

  2. 02

    Write the logic in plain English

    Each rule is agreed as a short statement, such as show the loyalty block only when tier is Gold or Silver, before any code is written.

  3. 03

    Build with fallbacks

    Every lookup, date and attribute has a defined behaviour when the data is missing or unexpected.

  4. 04

    Test across data shapes

    We preview and test send against subscribers chosen to cover each branch, including empty and edge-case records.

  5. 05

    Document and hand over

    Code is commented, variables are named clearly and a short note explains where each data dependency comes from.

Deliverables

ItemDescription
Personalisation specificationThe agreed rules for each dynamic element, in plain language
AMPscript codeCommented code in content blocks or templates, organised for reuse
Test matrixThe test subscribers used and the result for each branch
Troubleshooting notesKnown edge cases and how to diagnose them

Workflow diagram

Explore how the pieces fit together. Select a step to read what happens there.

Workflow

Send logging and troubleshooting

Open full size
Send logging and troubleshootingWhen a missing or wrong email is reported, the team queries the send log data extension. No row means the subscriber was excluded, so status and exclusions are checked. A row means the send happened, so the logged values are compared with source data to decide whether the data or the AMPscript needs fixing, then the fix is verified.Send logging and troubleshootingOps teamSend log DESubscriberrecordsYesNoDataCodeIssue reported: Missing or wrong email. A customer or colleague reports a missing email or wrong personalised content. Note the subscriber key, the email and the approximate send time.Issue reportedMissing or wrongemailQuery send log: By key and JobID. Send logging writes a row per subscriber per send with JobID, ListID, BatchID and any custom fields you add. A SQL query or filter finds the row.Query send logBy key and JobIDLogged at send time?. A row means the platform attempted the send to that subscriber. No row means they were excluded before sending, so the check moves to status and exclusions.Logged at sendtime?Check status: Unsubscribed, held, suppressed. Check the All Subscribers status, bounce history in the _Bounce data view, exclusion scripts and suppression lists. Most missing-email cases end here.Check statusUnsubscribed, held,suppressedCause found: Expected, or rule corrected. Either the exclusion was correct and is explained to the requester, or a wrong rule is corrected for future sends.Cause foundExpected, or rulecorrectedCompare values: Logged vs source. Custom send log fields capture AMPscript variables at send time. Comparing them with the source row shows whether the data or the code produced the wrong content.Compare valuesLogged vs sourceWrong data or code?. If the logged values match a wrong source record, the data is at fault. If the source was right but the output was wrong, the AMPscript logic is.Wrong data orcode?Fix source data: Then check sync or import. Correct the record at its source, not only in the data extension, or the next sync or import will bring the wrong value back.Fix source dataThen check sync orimportFix the AMPscript: Preview and test sends. Correct the logic, then preview as the affected subscriber and send tests. Handling empty values explicitly stops the same failure for others.Fix the AMPscriptPreview and testsendsFix verified: Resend only if appropriate. The fix is verified with a test send. Whether to resend depends on the message; a duplicate promotion can do more harm than the original error.Fix verifiedResend only ifappropriateStartProcess stepDecisionEnd or outcomeOriginal GeekMidst explanatory diagram, not an official Salesforce reference.

Select any step in the diagram, or use Step through, to see what happens at that point and why.

Text version: every step in order
  1. Issue reported Ops teamMissing or wrong email

    A customer or colleague reports a missing email or wrong personalised content. Note the subscriber key, the email and the approximate send time.

    Next: Query send log

  2. Query send log Send log DEBy key and JobID

    Send logging writes a row per subscriber per send with JobID, ListID, BatchID and any custom fields you add. A SQL query or filter finds the row.

    Next: Logged at send time?

  3. Logged at send time? Send log DE

    A row means the platform attempted the send to that subscriber. No row means they were excluded before sending, so the check moves to status and exclusions.

    Next: Yes: Compare values; No: Check status

  4. Check status Subscriber recordsUnsubscribed, held, suppressed

    Check the All Subscribers status, bounce history in the _Bounce data view, exclusion scripts and suppression lists. Most missing-email cases end here.

    Next: Cause found

  5. Cause found Subscriber recordsExpected, or rule corrected

    Either the exclusion was correct and is explained to the requester, or a wrong rule is corrected for future sends.

    End of the flow.

  6. Compare values Send log DELogged vs source

    Custom send log fields capture AMPscript variables at send time. Comparing them with the source row shows whether the data or the code produced the wrong content.

    Next: Wrong data or code?

  7. Wrong data or code? Send log DE

    If the logged values match a wrong source record, the data is at fault. If the source was right but the output was wrong, the AMPscript logic is.

    Next: Data: Fix source data; Code: Fix the AMPscript

  8. Fix source data Subscriber recordsThen check sync or import

    Correct the record at its source, not only in the data extension, or the next sync or import will bring the wrong value back.

    Next: Fix verified

  9. Fix the AMPscript Ops teamPreview and test sends

    Correct the logic, then preview as the affected subscriber and send tests. Handling empty values explicitly stops the same failure for others.

    Next: Fix verified

  10. Fix verified Ops teamResend only if appropriate

    The fix is verified with a test send. Whether to resend depends on the message; a duplicate promotion can do more harm than the original error.

    End of the flow.

When a missing or wrong email is reported, the team queries the send log data extension. No row means the subscriber was excluded, so status and exclusions are checked. A row means the send happened, so the logged values are compared with source data to decide whether the data or the AMPscript needs fixing, then the fix is verified. Original GeekMidst explanatory diagram; not an official Salesforce reference architecture.

Questions we hear

Should we use AMPscript or Server-Side JavaScript?
AMPscript is usually the better fit for email and simple CloudPages; SSJS suits API calls and more complex processing. Our AMPscript vs SSJS guide covers the trade-offs.
Can you fix an email that fails to send because of a script error?
Yes. We reproduce the error with the affected subscriber data, fix the cause and add guards so similar records do not break future sends.
Do you build preference centres?
Yes, using CloudPages and AMPscript, with care over consent capture and how changes flow back to your CRM.
Is heavy AMPscript a performance problem?
It can be. Many lookups per subscriber slow down large sends, so we often move work into SQL that prepares data before the send.

Need an AMPscript developer?

Share the email or CloudPage you need built or fixed, and we will scope the work with you.

Discuss your project →

Part of our Marketing Cloud work: Salesforce Marketing Cloud Consulting

Next step: AMPscript Development

  1. We read it A practitioner reads your message and replies by email.
  2. Short call We confirm goals, constraints and what success looks like.
  3. Written scope You get a scope and estimate before any work starts.

Tell us what you are trying to fix.

Share your Salesforce setup, goals and constraints. A practitioner reads every message and replies with questions, first thoughts or an honest view of whether you need outside help at all.

Talk to a Salesforce Expert
Book a Consultation