Git Product home page Git Product logo

salesforce_id_formatter's Introduction

Salesforce originally used case-sensitive 15-character alphanumeric IDs. Later on, added three error-correcting characters to make their 18-character ID.

Usage

SalesforceIdFormatter.to_18

  • 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

SalesforceIdFormatter.to_15

  • Applies the same rules as to_18, returning 15-char IDs instead.

SalesforceIdFormatter.valid_id?

  • Returns false if passed string is either not 15/18 characters or is not alphanumeric.

Attribution

Code is a modified version of https://gist.github.com/jbaylor-rpx/2691624 (original doesn't seem to calculate control digits correctly)

Installation

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

Development

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.

Contributing

  1. Fork it ( https://github.com/[my-github-username]/salesforce_id_formatter/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

salesforce_id_formatter's People

Contributors

maxbeizer avatar nstuart-at-salesforce avatar raul avatar svc-scm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

salesforce_id_formatter's Issues

Create a CLI executable

It would be nice if there were a CLI executable so I could convert IDs ad hoc.

I'm thinking something like:

$ salesforce_id_formatter 18, 'some_15_char_id'

raise when using bang (!) method

::to_18 raises when an id is invalid. That can make interacting with it require a good bit of rescue-ing.

Should we consider adding a new method ::to_18! that raises and have ::to_18 return nil?

WDYT @raul ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.