Skip to content

Instantly share code, notes, and snippets.

@dahse89
Last active October 26, 2016 12:16
Show Gist options
  • Save dahse89/49bfd1bcd08b6c68d880d7e67e228b5c to your computer and use it in GitHub Desktop.
Save dahse89/49bfd1bcd08b6c68d880d7e67e228b5c to your computer and use it in GitHub Desktop.
salesforce 15 digit to 18 digit id. Function to calculate the checksum.
<?php
function salesForceIdChecksum($id)
{
$map = implode('',array_merge(range('A', 'Z'), range(0, 9)));
$checksum = '';
foreach (str_split($id, 5) as $chunk) {
$checksum .= substr($map, bindec( strrev(array_reduce(str_split($chunk, 1),function($carry, $item){
$carry .= (!is_numeric($item) && $item == strtoupper($item)) ? '1' : '0';
return $carry;
},''))),1);
}
return $checksum;
}
// example
//$_15ID = '001b000000dA3YY';
//$_18ID = $_15ID. salesForceIdChecksum($_15ID);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment