Skip to content

Instantly share code, notes, and snippets.

@SergioCC14
Created April 28, 2017 10:39
Show Gist options
  • Select an option

  • Save SergioCC14/32248c3e31b91504ef0f175980fae85b to your computer and use it in GitHub Desktop.

Select an option

Save SergioCC14/32248c3e31b91504ef0f175980fae85b to your computer and use it in GitHub Desktop.
Example: restforce integration for Rails App
class Restforce
attr_reader :client
def initialize
@client = initialize_client
@client.authenticate!
end
def initialize_client
config = Rails.application.secrets.salesforce
Restforce.new(
security_token: config["security_token"],
client_secret: config["client_secret"],
client_id: config["client_id"],
api_version: config["api_version"]
username: config["username"],
password: config["password"],
host: config["host"]
)
end
def obtain_account(model, id_externo)
client.find(model, id_externo)
end
def destroy_account(model, id_externo)
client.destroy(model, id_externo)
end
def obtain_description_from_account(id_externo)
client.query("select Description from Account where External__c = '#{id_externo}'").first
end
def create_or_update_account(account)
client.upsert!('Account', 'External__c',
Name: account.id.to_s,
External__c: account.id.to_s,
Description: account.description
)
end
end
salesforce:
username: 'username@example.com'
password: 'password123'
security_token: 'security_token'
client_id: 'client_id'
client_secret: 'client_secret'
account_id: 'account_id'
host: 'login.salesforce.com'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment