Class: SObjectModel::Adapter::Sf

Inherits:
Base
  • Object
show all
Defined in:
lib/sobject_model/adapter/sf.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sf_main, target_org:) ⇒ Sf

Returns a new instance of Sf.



8
9
10
11
# File 'lib/sobject_model/adapter/sf.rb', line 8

def initialize(sf_main, target_org:)
  @sf = sf_main
  @target_org = target_org
end

Instance Attribute Details

#target_orgObject (readonly)

Returns the value of attribute target_org.



6
7
8
# File 'lib/sobject_model/adapter/sf.rb', line 6

def target_org
  @target_org
end

Instance Method Details

#create(object_type, values, klass = nil) ⇒ Object



21
22
23
24
25
26
# File 'lib/sobject_model/adapter/sf.rb', line 21

def create(object_type, values, klass = nil)
  id = sf.data.create_record object_type, values: values, target_org: target_org
  return id if klass.nil?

  find(object_type, id, klass)
end

#delete(object_type, id) ⇒ Object



32
33
34
# File 'lib/sobject_model/adapter/sf.rb', line 32

def delete(object_type, id)
  sf.data.delete_record object_type, record_id: id, where: nil, target_org: target_org
end

#describe(object_type) ⇒ Object



40
41
42
43
# File 'lib/sobject_model/adapter/sf.rb', line 40

def describe(object_type)
  schema = sf.sobject.describe(object_type, target_org: target_org)
  schema.to_h # convert to raw command response
end

#exec_query(soql, format: nil, bulk: false, wait: nil, model_class: nil) ⇒ Object



13
14
15
# File 'lib/sobject_model/adapter/sf.rb', line 13

def exec_query(soql, format: nil, bulk: false, wait: nil, model_class: nil)
  sf.data.query(soql, target_org: target_org, format: format, bulk: bulk, wait: wait, model_class: model_class)
end

#find(object_type, id, klass) ⇒ Object



17
18
19
# File 'lib/sobject_model/adapter/sf.rb', line 17

def find(object_type, id, klass)
  sf.data.get_record object_type, record_id: id, target_org: target_org, model_class: klass
end

#query(soql, klass, format = nil) ⇒ Object



36
37
38
# File 'lib/sobject_model/adapter/sf.rb', line 36

def query(soql, klass, format = nil)
  sf.data.query soql, target_org: target_org, format: format, model_class: klass
end

#update(object_type, id, values) ⇒ Object



28
29
30
# File 'lib/sobject_model/adapter/sf.rb', line 28

def update(object_type, id, values)
  sf.data.update_record object_type, record_id: id, where: nil, values: values, target_org: target_org
end