Class: SfConnect::Fields

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

Overview

salesforce fields <=> object attributes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(salesforce_object_name:, where:, fields:, block:) ⇒ Fields

Returns a new instance of Fields.



8
9
10
11
12
13
14
15
16
# File 'lib/sf_connect/fields.rb', line 8

def initialize(salesforce_object_name:, where:, fields:, block:)
  @fields = fields
  @salesforce_object_name = salesforce_object_name
  @query = "select #{fields.keys.join(",")} from #{salesforce_object_name}"
  @query = "#{@query} where #{where}" if where

  @payload = Class.new(SfConnect::Payload)
  @payload.include(Module.new(&block)) if block
end

Instance Attribute Details

#salesforce_object_nameObject (readonly)

Returns the value of attribute salesforce_object_name.



6
7
8
# File 'lib/sf_connect/fields.rb', line 6

def salesforce_object_name
  @salesforce_object_name
end

Instance Method Details

#fetch(id, field = nil) ⇒ Object



18
19
20
# File 'lib/sf_connect/fields.rb', line 18

def fetch(id, field = nil)
  payload_for_download(SfConnect.find(salesforce_object_name, id, field))
end

#fetch_all(query_option) ⇒ Object



22
23
24
25
26
# File 'lib/sf_connect/fields.rb', line 22

def fetch_all(query_option)
  SfConnect.query(@query + query_option).each do |sobject|
    yield payload_for_download(sobject)
  end
end

#payload_for_download(record) ⇒ Object



36
37
38
# File 'lib/sf_connect/fields.rb', line 36

def payload_for_download(record)
  @payload.new(record:, for_download: convert_from_salesforce(record))
end

#payload_for_upload(record) ⇒ Object



32
33
34
# File 'lib/sf_connect/fields.rb', line 32

def payload_for_upload(record)
  @payload.new(record:, for_upload: convert_to_salesforce(record)).for_upload
end

#payload_for_upload_from_hash(record) ⇒ Object



28
29
30
# File 'lib/sf_connect/fields.rb', line 28

def payload_for_upload_from_hash(record)
  @payload.new(record:, for_upload: convert_to_salesforce_from_hash(record)).for_upload
end