SalesforceFsdb

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

Note

This module is in maintenance only mode and in future will only be updated with bug fixes. As of 0.0.6, this module has been renamed to SalesforceCache and thus that is recommended for future use. Migration should be straight-forward from SalesforceFsdb 0.0.4 / 0.0.5 to SalesforceCache 0.0.6. The new name will enable future support for multiple backends, in addition to the file system.

Installation

Gem Installation

Download and install salesforce_fsdb with the following:

gem install salesforce_fsdb

Usage

require 'salesforce_fsdb'

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.

Redirection

In the event an Account sObject request results in a NOT_FOUND error for a given Salesforce Id, the library will attempt to use the Id as an Opportunity Id and, if successful, will return the proper Account sObject.

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.