Created
December 21, 2014 05:01
-
-
Save kirley/799cb893621a47c6dd85 to your computer and use it in GitHub Desktop.
Convert 15 digit Salesforce ID to 18 digit Salesforce ID
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# convert 15 digit SFDC ID to 18 digit | |
def convert_salesforce_id(id) | |
if id.try(:length) == 15 | |
chunks = id.chars.to_a | |
char_map = %w{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5} | |
extension = [] | |
chunks.each_slice(5) { |x| y = x.reverse.map {|c| (c.match /[A-Z]/) ? 1 : 0 }.join("").to_i(2) ; extension << y} | |
id = id + (extension.map {|e| char_map.at(e)}).join("").to_s | |
end | |
id | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment