LongSFID
Converts a 15-character case-sensitive Salesforce ID to the 18-character case-insensitive version. Runtime-proven on a live Marketing Cloud Engagement CloudPage — including that a non-15-character input is passed straight through unchanged instead of being validated.
Syntax
LongSFID(sfid15) → string
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
sfid15 |
string | Yes | 15-character case-sensitive Salesforce record ID |
Example
%%[
VAR @longId
SET @longId = LongSFID("0036000000QKv5T")
]%%
Long ID: %%=v(@longId)=%%
Renders Long ID: 0036000000QKv5TAAT.
Marketing Cloud cannot store a raw 15-character Salesforce ID in a data extension, so convert it before writing or matching on it — for example when an ID arrives on a landing-page query string:
%%[
VAR @longId
SET @longId = LongSFID(RequestParameter("id"))
]%%
Return value
string — the 18-character case-insensitive Salesforce ID for a valid 15-character input.
There is no closed set of sentinel values: the result is the input ID with a computed 3-character checksum appended. For any input that is not exactly 15 characters the return is the input itself, unchanged (see below).
Behaviour
A valid 15-character ID gains a 3-character checksum. LongSFID("0036000000QKv5T") gives 0036000000QKv5TAAT, LongSFID("00Q6F00001APnym") gives 00Q6F00001APnymUAD, and LongSFID("001500000ABCDEF") gives 001500000ABCDEFAQ5. The result is always 18 characters long.
A non-15-character input is passed through unchanged
Neither reference says what happens for anything other than a 15-character ID. In practice the function does not validate the length — it appends the checksum only to a genuine 15-character ID and otherwise returns the argument untouched, with no error.
| Call | Renders | Length |
|---|---|---|
LongSFID("0036000000QKv5TAAT") |
0036000000QKv5TAAT |
18 |
LongSFID("ABC") |
ABC |
3 |
LongSFID("") |
(empty) | 0 |
An already-18-character ID is returned as-is rather than transformed a second time, a too-short value comes back unchanged, and an empty string stays empty. Do not rely on the result being 18 characters, and guard the input length yourself if an invalid ID must be rejected. The finding is catalogued on Differs from official docs.
Show test script
%%[
VAR @b
SET @b = RequestParameter("b")
/* safe sweep: three known-answer 15-char IDs, all accepted */
IF @b == "safe" THEN
OutputLine(Concat("LongSFID('0036000000QKv5T')=[", LongSFID("0036000000QKv5T"), "]"))
OutputLine(Concat("LongSFID('00Q6F00001APnym')=[", LongSFID("00Q6F00001APnym"), "]"))
OutputLine(Concat("LongSFID('001500000ABCDEF')=[", LongSFID("001500000ABCDEF"), "]"))
ENDIF
/* an already-18-char ID is returned unchanged, not transformed again */
IF @b == "already18" THEN
OutputLine(Concat("already18=[", LongSFID("0036000000QKv5TAAT"), "] len=[", Length(LongSFID("0036000000QKv5TAAT")), "]"))
ENDIF
/* a too-short input is passed through unchanged, no error */
IF @b == "short" THEN
OutputLine(Concat("short=[", LongSFID("ABC"), "] len=[", Length(LongSFID("ABC")), "]"))
ENDIF
/* an empty string is passed through unchanged */
IF @b == "empty" THEN
OutputLine(Concat("empty=[", LongSFID(""), "] len=[", Length(LongSFID("")), "]"))
ENDIF
]%%
OutputLine given a bare string literal renders an empty line. Wrap the argument in Concat() or your start and done markers vanish silently — which looks exactly like the function failing.
Availability
| Platform | Available |
|---|---|
| Marketing Cloud Engagement | Yes |
| Marketing Cloud Next | No |
See also
- Differs from official docs — the silent pass-through finding in full
- Official reference · ampscript.guide