SalesforceFsdb

Salesforce SObject system to retrieve and cache queries from Salesforce.com including SObjects and SOQL results.

Installation

Gem Installation

Download and install salesforce_fsdb with the following:

gem install salesforce_fsdb

Usage

require 'salesforce_fsdb/client'

paramsGeneral    =  {
  :api_fqdn      => 'na1.salesforce.com',
  :api_version   => '29.0',
  :data_dir      => '/path/to/sf_data',
  :max_age       => 60*60*24*7
}

paramsToken      =  {
  :grant_type    => 'password',
  :client_id     => 'my_client_id',
  :client_secret => 'my_client_secret',
  :username      => 'my_username',
  :password      => 'my_password'
}

# using the filesystem cache with max_age
sfFsdbClient = SalesforceFsdb::Client.new(paramsGeneral,paramsToken)
sObjectHash  = sfFsdbClient.getSobjectForSfidAndType('my_sobject_id','Account')

sSfid = '1234567890'
sSoql = %{ SELECT Id,AccountId,Name,IsWon,StageName,CloseDate from Opportunity where AccountId='#{sSfid}' }
sPath = "AccountOpportunities/sf_act_#{sSfid}_opps.jff"

dResults = sfFsdbClient.getResForSoqlAndPath( sSoql, sPath )

# without using a filesystem cache
sfRestClient = SalesforceFsdb::RestClient.new(paramsGeneral,paramsToken)
sObjectHash  = sfRestClient.getSobjectForSfidAndType('my_sobject_id','Account')

Notes

Max Age

The :max_age parameter is used to indicate the maximum age in seconds for cached data. If local data exceeds maximum age, a new copy of the data is retrieved from Salesforce.com. To ensure retrieval of a new copy, use :max_age=-1.

Directory Paths

Salesforce Sobjects are stored on the file system under File.join( paramsGeneral, Sobject_type ).

SOQL results are stored in the path indicated. Sub-directories are created for SOQL paths. If a relative directory is provided, it is appended to the :data_dir. If an absolute directory is provided, it is used as an absolute directory in its entirety.

Object Size

Some large Salesforce Objects may generate Salesforce errors. A future release will allow specifying specific fields for retrieval.

Salesforce REST API Reference

www.salesforce.com/us/developer/docs/api_rest/

Problems, Comments, Suggestions?

All of the above are most welcome. [email protected]

Credits

John Wang - johnwang.com

License

SalesforceFsdb is available under an MIT-style license.

:include: MIT-LICENSE

Warranty

This software is provided “as is” and without any express or implied warranties, including, without limitation, the implied warranties of merchantibility and fitness for a particular purpose.