© STUDYR.
ORG
AMPscript
For Salesforce Marketing Cloud
Best Practices
© STUDYR.ORG
Best Practices
Be organized
As you will see, your code can become quite long quite quickly.
Indenting* your code makes it easier to troubleshoot.
*Indentation involves using the same width of whitespace before each line of a group of code
so that they appear to be related.
© STUDYR.ORG
Best Practices
Be literal
When naming objects and variables, don’t take shortcuts*. In a few
years time, when your code breaks and you need to fix it urgently,
will you remember what the acronym ‘clls’ was supposed to mean?
* Rule of thumbs is:
No acronyms.
No abbreviations.
No approximations.
No spaces.
© STUDYR.ORG
Best Practices
Be case consistent
AMPscript is NOT case sensitive, it will understand @firstname and
@FirstName as the same object. But other programs coming into
play further down the road, like SSJS, will not and inconsistent
capitalisation can cause headaches.
© STUDYR.ORG
Best Practices
Be Picky
When your code becomes very long, you will be tempted to edit it
outside of Marketing Cloud.
Make sure you pick a Code Editor (like VS Code, Brackets) and not a
Text Editor to do so. Text editors tend to use fancy quotes that will
confuse Marketing Cloud – and break your code.
© STUDYR.ORG
Best Practices
Be Patient
Writing code shouldn't be a sprint, it's more like a stroll through the
park. So, proceed with care, test often – one line at a time if possible
– to catch bugs early
© STUDYR.ORG
Good luck!