Class: SalesforceIntegration::SalesforceIntegrationLead

Inherits:
Object
  • Object
show all
Defined in:
lib/salesforceintegration.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ SalesforceIntegrationLead



9
10
11
12
13
14
15
16
17
# File 'lib/salesforceintegration.rb', line 9

def initialize(options)
  raise "It's necessary to inform client_id, client_secret, url, username and password!" unless options.has_key?(:client_id) and options.has_key?(:client_secret) and options.has_key?(:url) and options.has_key?(:username) and options.has_key?(:password)

  client = Databasedotcom::Client.new(:client_id => options[:client_id], :client_secret => options[:client_secret], :host => options[:url])
  client.authenticate(:username => options[:username], :password => options[:password])

  client.materialize("Lead")
  client.materialize("User")
end

Instance Method Details

#create_lead_on_salesforce(fields) ⇒ Object

TODO: Permitir associar a contas



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/salesforceintegration.rb', line 20

def create_lead_on_salesforce(fields)
  raise "The fields last_name and company are required"    unless fields.has_key?(:last_name) and fields.has_key?(:company)
  raise "The fields last_name and company cannot be blank"     if fields[:last_name].blank?    or fields[:company].blank? 

  lead = Lead.new

  #TODO: Nao esta claro ao que corresponde esse usuario no salesforce. Verificar
  user = User.first
  lead['OwnerId'] = user.Id

  lead['FirstName'] = fields[:first_name]
  lead['LastName'] = fields[:last_name]
  lead['Email'] = fields[:email]
  lead['Company'] = fields[:company]
  lead['Title'] = fields[:job_title]
  lead['Phone'] = fields[:phone]
  lead['Website'] = fields[:website]
  lead['IsConverted'] = false
  lead['IsUnreadByOwner'] = true
  lead.save
  lead.Id
end