Class: Salesforce::SfBase
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Salesforce::SfBase
- Defined in:
- lib/salesforce/sf_base.rb
Overview
SfBase is the mother of all other objects. It establishes the SOAP connection to Salesforce Server and turns it into A/R objects. Main methods are:
1. self.loging (username, password, security_token) -> static method
2. logout (session {as both single or hash}) -> instance method
3. self.swap_connction(connection) -> static method
4. self.query_by_sql(sql) -> static method
For complete list of Salesforce Standard Objects in V20.
Direct Known Subclasses
Account, AccountFeed, ApexLog, Asset, AssetFeed, Campaign, CampaignFeed, Case, CaseFeed, CaseTeamMember, CaseTeamRole, Contact, ContactFeed, Contract, ContractFeed, EntitySubscription, FeedComment, FeedPost, FeedTrackedChange, Group, GroupMember, Lead, LeadFeed, NewsFeed, Opportunity, OpportunityFeed, Organization, Product2, Product2Feed, Solution, SolutionFeed, SolutionHistory, Task, TaskFeed, User, UserFeed, UserProfileFeed, UserRole
Instance Attribute Summary collapse
-
#connection_owner ⇒ Object
readonly
Returns the owner’s info of the current Salesforce WS connection.
-
#current_connection ⇒ Object
readonly
Return a read only version of the current_connection.
-
#current_connection_binding ⇒ Object
readonly
Return a read-only version of the binding associated with the current connection.
Class Method Summary collapse
-
.login(user, pass, token) ⇒ Object
By default the ‘salesforce-default-realm’ in the ‘database.yml’ is the default connection, meaning all Salesforce objects will use that for the A/R connection.
-
.query_by_sql(sql) ⇒ Object
Provides a method to directly call SQL via RFORCe.
-
.swap_connection(connection) ⇒ Object
Swaps the connection to Salesforce.
Instance Method Summary collapse
-
#logout(session_ids = Hash.new) ⇒ Object
Logs out of the Salesforce session.
Methods inherited from ActiveRecord::Base
activesalesforce_connection, debug, flush_connections
Instance Attribute Details
#connection_owner ⇒ Object (readonly)
Returns the owner’s info of the current Salesforce WS connection
84 85 86 |
# File 'lib/salesforce/sf_base.rb', line 84 def connection_owner @connection_owner end |
#current_connection ⇒ Object (readonly)
Return a read only version of the current_connection
79 80 81 |
# File 'lib/salesforce/sf_base.rb', line 79 def current_connection @current_connection end |
#current_connection_binding ⇒ Object (readonly)
Return a read-only version of the binding associated with the current connection
89 90 91 |
# File 'lib/salesforce/sf_base.rb', line 89 def current_connection_binding @current_connection_binding end |
Class Method Details
.login(user, pass, token) ⇒ Object
By default the ‘salesforce-default-realm’ in the ‘database.yml’ is the default connection, meaning all Salesforce objects will use that for the A/R connection. However, a web application is designed to support multiple users. Therefore, each user should have his/her own connection. To do that, the web-application should use the ‘before-filter’ to swap contexts/connections for each user. A good place to put that filter is in the ‘application_controller.rb’ file. The context can be changed for 1) a single SF class. Or 2) the root (SfObject), it will affect every other class inherited from the SfObject.
41 42 43 44 45 46 47 48 |
# File 'lib/salesforce/sf_base.rb', line 41 def self.login(user, pass, token) params = {:adapter => "activesalesforce", :url => "https://login.salesforce.com/services/Soap/u/20.0", :username => user, :password => pass + token } self.establish_connection(params) end |
.query_by_sql(sql) ⇒ Object
Provides a method to directly call SQL via RFORCe
71 72 73 74 |
# File 'lib/salesforce/sf_base.rb', line 71 def self.query_by_sql(sql) query_results = connection.binding.query :searchString => sql return query_results.queryResponse.result.records unless query_results.queryResponse.result.size < 1 end |
.swap_connection(connection) ⇒ Object
Swaps the connection to Salesforce
66 67 68 |
# File 'lib/salesforce/sf_base.rb', line 66 def self.swap_connection (connection) @@connection = connection end |
Instance Method Details
#logout(session_ids = Hash.new) ⇒ Object
Logs out of the Salesforce session
51 52 53 54 55 56 57 58 59 |
# File 'lib/salesforce/sf_base.rb', line 51 def logout(session_ids=Hash.new) result = SfBase.connection.binding.invalidateSessions(session_ids) if"invalidateSessionsResponse" == result.to_s return true else return false end #result this.connection.binding.logout(Hash.new) end |