Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
EncodingUtil Class
Namespace
Usage
EncodingUtil Methods
The following are methods for EncodingUtil. All methods are static.
convertFromHex(inputString)
Signature
public static Blob convertFromHex(String inputString)
Parameters
- inputString: Type: String The hexadecimal string to convert. The string can contain only valid hexadecimal characters (0-9, a-f, A-F) and must have an even number of characters.
Return Value
Type: Blob
Usage
Each byte in the Blob is constructed from two hexadecimal characters in the input string.
The convertFromHex method throws the following exceptions.
- NullPointerException — the inputString is null.
- InvalidParameterValueException — the inputString contains invalid hexadecimal characters or doesn’t contain an even number of characters.
Example
1Blob blobValue = EncodingUtil.convertFromHex('4A4B4C');
2System.assertEquals('JKL', blobValue.toString());convertToHex(inputBlob)
Signature
public static String convertToHex(Blob inputBlob)
Parameters
- inputBlob: Type: Blob
Return Value
Type: String
urlDecode(inputString, encodingScheme)
Signature
public static String urlDecode(String inputString, String encodingScheme)
Return Value
Type: String
Usage
This method uses the supplied encoding scheme to determine which characters are represented by any consecutive sequence of the form \"%xy\". For more information about the format, see The form-urlencoded Media Type in Hypertext Markup Language - 2.0.
urlEncode(inputString, encodingScheme)
Signature
public static String urlEncode(String inputString, String encodingScheme)
Return Value
Type: String
Usage
The rules that apply when the method encodes a string:
- These characters remain the same:
- Alphanumeric characters A - Z, a - z, and 0 -9.
- Special characters dot (.), hyphen (-), asterisk (*), and under score (_).
- The space character is converted to a plus sign (+).
- All other characters are unsafe. This method uses the supplied encoding scheme to obtain the bytes for unsafe characters. For more information about the format, see The form-urlencoded Media Type in Hypertext Markup Language - 2.0.
Example
1String encoded = EncodingUtil.urlEncode(url, 'UTF-8');