Salesforce originally used case-sensitive 15-character alphanumeric IDs. Later on, added three error-correcting characters to make their 18-character ID.
- Converts a 15-char String to its equivalent 18-char ID as a String: `SalesforceIdFormatter.to_18('70130000001tcyI') # => '70130000001tcyIAAQ'``
- Leaves a 18-char String unaltered:
SalesforceIdFormatter.to_18('70130000001tcyIAAQ') # => '70130000001tcyIAAQ'
- Raises
SalesforceIdFormatter::InvalidId
if the given ID doesn't follow Salesforce's conventions http://www.salesforce.com/us/developer/docs/api/Content/field_types.htm#i1435616 TL;DR: 15 or 18 alphanumeric, case-sensitive chars
- Applies the same rules as
to_18
, returning 15-char IDs instead.
- Returns false if passed string is either not 15/18 characters or is not alphanumeric.
Code is a modified version of https://gist.github.com/jbaylor-rpx/2691624 (original doesn't seem to calculate control digits correctly)
Add this line to your application's Gemfile:
gem 'salesforce_id_formatter'
And then execute:
$ bundle
Or install it yourself as:
$ gem install salesforce_id_formatter
After checking out the repo, run bin/setup
to install dependencies. Then, run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
to create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
- Fork it ( https://github.com/[my-github-username]/salesforce_id_formatter/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request