The Salesforce Developers website will undergo maintenance on May 29, 2024 from 3:00 a.m. UTC to 10:00 a.m. UTC. The maintenance process may affect the availability of our documentation. Please plan accordingly.

BarCodeUrl()

Generates a barcode based on an input string. Most of the barcode types that the function can generate are linear (one-dimensional), although it can generate two-dimensional Data Matrix and PDF417 codes. The function can’t currently be used to create QR codes.

You can call this function up to two times per message or landing page.

The BarCodeURL() function has nine parameters:

  • valueToConvert (string): Required. The value to convert into a barcode.
  • barcodeType (string): Required. The type of barcode to create. See Supported Barcode Types for a list of possible values.
  • width (number): Required. The width of the barcode in pixels.
  • height (number): Required. The height of the barcode in pixels.
  • checksumValue (string): A checksum value for the barcode.
  • boolShowText (boolean): If true or 1, the function includes the text of valueToConvert under the barcode.
  • altText (string): Alternate text to display under the barcode. The function only adds the specified text to the barcode when the value of boolShowText is false.
  • rotation (number): Orientation of the barcode in degrees. Accepted values: 0, 90, 180, 270.
  • boolTransparentBG (boolean): If true or 1, the barcode includes a transparent background. Otherwise, the background is white.

The BarCodeUrl() function supports a variety barcode encoding standards. This table describes the features and limitations of each supported barcode type.

CodeNameTypeCharacter LimitAllowed CharactersNotes
codabarCodabarLinearVariableUppercase letters A–D, numbers 0–9, and these characters: - $ : / . +Must begin and end with a letter A–D
code11Code 11LinearVariableNumbers 0–9 and -
code128autoCode 128 AutoLinearVariableAll ASCII characters
code128aCode 128 ALinearVariableUppercase ASCII characters, numbers 0–9, and ASCII special characters
code128bCode 128 BLinearVariableUppercase and lowercase ASCII characters, numbers 0–9, and ASCII special characters
code128cCode 128 CLinearVariableNumbers 0–9
code39Code 39LinearVariableUppercase letters (A–Z), numbers (0-9), spaces, and these characters: - . $ / + %
code39extCode 39 ExtendedLinearVariableAny character in the extended ASCII character set
code93Code 93LinearVariableUppercase letters (A–Z), numbers (0-9), spaces, and these characters: - . $ / + %
code93extCode 93 ExtendedLinearVariableAll ASCII characters
datamatrixData MatrixTwo-dimensional1556 bytesAll extended ASCII charactersBinary encodings aren’t supported
ean13EAN 13Linear13 digitsNumbers 0–9
ean8EAN 8Linear8 digitsNumbers 0–9
industr25Code 25 IndustrialLinearVariableNumbers 0–9
interl25Code 25 InterleavedLinearVariableNumbers 0–9
msiMSI PlesseyLinearVariableNumbers 0–9
pdf417PDF 417Two-dimensional1108 bytesAll extended ASCII charactersBinary encodings aren’t supported
upcaUPC ALinear12 digitsNumbers 0–9
upceUPC ELinear12 digitsNumbers 0–9Identical to UPC A in this implementation

The function lets you specify some barcode types that aren’t supported. If you specify any of the values in this list, the function doesn’t produce an exception, but it also doesn’t output a barcode.

  • mat25
  • onecode
  • plaintext
  • planet
  • postnet
  • telepen

To call the function, pass the string that you want to encode, the barcode type to use, and the width and height of the barcode, along with any optional arguments. Some barcode types, such as EAN 8 or UPC A, only accept a certain number of characters. When you use a non-variable-length barcode type, and you include an incorrect number of characters, the function doesn’t render the barcode.

If you call the function using optional parameters, you must include all of the parameters that precede it. For example, if you want to include the altText parameter, you must also include the checksumValue and boolShowText parameters. In this situation, you can pass empty strings if it's unnecessary to provide a string value. Continuing the example, if it's unnecessary to provide a value for the checksumValue parameter because the barcode type you selected includes a checksum by default, you can pass an empty string.

To render the barcode, enclose the function code in an HTML <img> tag. This example creates a Code 128 Auto barcode that includes the URL of the Salesforce website.

The rendered HTML email or landing page includes this barcode.

A Code 128 Auto barcode, with https://www.salesforce.com printed below it.

This example creates a Code 128 Auto barcode in which the encoded data is the URL of the Salesforce website. Rather than print the same text below the barcode, this example uses the altText parameter to specify a different printed string.

Code 128 Auto barcodes include an internal check digit by default, so you can pass an empty string for the checksumValue parameter.

The rendered HTML email or landing page includes this barcode.

A Code 128 Auto barcode, with the text "Salesforce Website" printed below it.

This example creates a Code 128 Auto barcode that is rotated 90° clockwise.

The rendered HTML email or landing page includes this barcode.

A Code 128 Auto barcode, with the text "Salesforce Website" printed below it. The barcode and the text below it are rotated clockwise 90 degrees.