Skip to content

Instantly share code, notes, and snippets.

@noeticpenguin
Created October 6, 2011 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noeticpenguin/1268675 to your computer and use it in GitHub Desktop.
Save noeticpenguin/1268675 to your computer and use it in GitHub Desktop.
Salesforce 15 to 18 digit guid conversion
def convert_guid(short_guid)
chunks = short_guid.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}
short_guid + (extension.map {|e| char_map.at(e)}).join("").to_s
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment