1.0.0 • Published 8 years ago
salesforce-id-validator v1.0.0
salesforce-id-validator
A Library to validate and convert to Salesforce 18IDs
Install via NPM
npm install --save salesforce-id-validatorUsage
Validate a given ID18
const salesforceIdValidator = require('salesforce-id-validator');
salesforceIdValidator.validateId18('001A00000006Vm9uIAC');
{
valid: true,
error: null,
meta: {
entityType: 'ACCOUNT',
serverId: 'A0',
identifier: '0000006Vm9u',
extractedChecksum: 'IAC',
calculatedChecksum: 'IAC'
}
}Generate a ID18 from a ID15
const salesforceIdValidator = require('salesforce-id-validator');
salesforceIdValidator.generateId18FromId15('001A00000006Vm9u');
{
valid: true,
error: null,
id18: '001A00000006Vm9uIAC'
}Using Validator in browser
Grab a copy of either salesforce-id-validator.js or the minified version
salesforce-id-validator.min.js and add it to your HTML file like this:
<script src=".../salesforce-id-validator.min.js"></script>It will automatically hook into the window object and can be accessed like this
window.salesforceIdValidator.validateId18( ... )CAVEAT
DON'T USE THE RESULT IN AN IF CLAUSE, BECAUSE IT WILL ALWAYS EVALUATE TO TRUE SINCE IT'S AN OBJECT!!!
Errors
ID_IS_NOT_A_STRING: id is not a stringINVALID_LENGTH: id not 18 characters long, 15 if you are usinggenerateId18FromId15functionINVALID_CHARACTERS: id contains invalid characters; (only[0-9a-zA-Z])INVALID_PREFIX: prefix unkown to salesforceINVALID_CHECKSUM: checksum calculation doesn't match with the provided one