Taking ErlForce for a Spin

If Java is a Ford F-150 pickup truck – mainstream, ubiquitous, utilitarian – and Ruby is a Mazda Miata – great handling, and just a little 'out there' – then Erlang is a Porsche 911 GT2 – incredible engineering, but probably not for everyone. Written at Ericsson in the mid-eighties and open sourced in 1998, Erlang is a functional language and runtime environment designed for highly concurrent, fault-tolerant services, the more '9's the better. Originally intended for telephony systems, it's now seeing wider use in a variety of distributed applications such as CouchDB, RabbitMQ and SimpleDB.

Ian Brown, not the former lead signer of The Stone Roses, but an R&D manager at salesforce.com, dropped me a note on Chatter the other day to say that he's been moonlighting on ErlForce, an Erlang client library for the Force.com API*, and would I like to take it for a spin? How could I refuse!? With the Erlang getting started guide in hand, I managed to cobble together a working sample in just a couple of hours – my first Erlang app, test.erl:

-module(test).
-export([test/3]).

test(Username, Password, SecretToken) ->
    application:start(inets),
    application:start(crypto),
    application:start(public_key),
    application:start(ssl),
    [{sessionId, SessionId}, {serverUrl,Endpoint}]=sfdc:login(Username, Password, SecretToken),
    {_, _, _, Records}=sfdc:soql_query("select Id, Name from Account", SessionId, Endpoint),
    PrintRecord=fun(Record)->
              [_,{"Id",_,Id},_,{"Name",_,Name}]=Record,
          io:format("~s ~s~n",[Id, Name])         
      end,
    lists:foreach(PrintRecord, Records).

 

There's a bit of housekeeping to load various required components, then I use the sfdc module's login function to get a session ID and API endpoint, execute a query to retrieve my Account IDs and names, and print them out. Running this in the Erlang interpreter gives very familiar results:

Erlang R14B01 (erts-5.8.2) [source] [64-bit] [smp:4:4] [rq:4] [async-threads:0] 
[hipe] [kernel-poll:false]


Eshell V5.8.2  (abort with ^G)
1> c(sfdc).
./sfdc.erl:20: Warning: http:request/4 is deprecated and will be removed in R15B; use httpc:request/4
./sfdc.erl:291: Warning: variable 'RecordTypeIds' is unused
./sfdc.erl:839: Warning: http:request/4 is deprecated and will be removed in R15B; use httpc:request/4
{ok,sfdc}
2> c(test).
{ok,test}
3> test:test("user@example.com","password","security_token").
0015000000VALDtAAP GenePoint
0015000000VALDuAAP United Oil & Gas, UK
0015000000VALDvAAP United Oil & Gas, Singapore
0015000000VALDwAAP Edge Communications
0015000000VALDxAAP Burlington Textiles Corp of America
0015000000VALDyAAP Pyramid Construction Inc.
0015000000VALDzAAP Dickenson plc
0015000000VALE0AAP Grand Hotels & Resorts Ltd
0015000000VALE1AAP Express Logistics and Transport
0015000000VALE2AAP University of Arizona
0015000000VALE3AAP United Oil & Gas Corp.
0015000000VALE4AAP sForce
ok

 

Ian describes ErlForce as 'pretty beta', so I wouldn't bet your business on it quite yet, but certainly go check it out. If you're already an Erlang fan, you'll be able to easily access your data in Force.com; if not, this is a great excuse to broaden your horizons and try a little functional programming 🙂

* For the record, this is Ian's own personal project and is no way affiliated with, supported or endorsed by salesforce.com. Except that it's cool technology that leverages the Force.com platform, and we're all for that!

 

Published
January 27, 2011
Topics:

Leave your comments...

Taking ErlForce for a Spin