Class: Remi::DataTarget::Salesforce

Inherits:
Remi::DataTarget show all
Includes:
Remi::DataSubject::Salesforce
Defined in:
lib/remi/data_subject/salesforce.rb

Instance Attribute Summary

Attributes inherited from Remi::DataSubject

#fields

Instance Method Summary collapse

Methods included from Remi::DataSubject::Salesforce

#field_symbolizer, #restforce_client

Methods inherited from Remi::DataTarget

#load

Methods inherited from Remi::DataSubject

#df, #df=, #enforce_types, #field_symbolizer

Constructor Details

#initialize(*args, **kargs, &block) ⇒ Salesforce

Returns a new instance of Salesforce.



97
98
99
100
# File 'lib/remi/data_subject/salesforce.rb', line 97

def initialize(*args, **kargs, &block)
  super
  init_salesforce(*args, **kargs, &block)
end

Instance Method Details

#load!Object

Public: Performs the load operation, regardless of whether it has already executed.

Returns true if the load operation was successful



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/remi/data_subject/salesforce.rb', line 106

def load!
  @logger.info "Performing Salesforce #{@operation} on object #{@sfo}"

  df_as_array_of_hashes = df.to_a[0] # This probably wouldn't work with a non-Daru df
  if @operation == :update
    Remi::SfBulkHelper::SfBulkUpdate.update(restforce_client, @sfo, df_as_array_of_hashes, batch_size: @batch_size, logger: @logger)
  elsif @operation == :create
    Remi::SfBulkHelper::SfBulkCreate.create(restforce_client, @sfo, df_as_array_of_hashes, batch_size: @batch_size, logger: @logger)
  elsif @operation == :upsert
    Remi::SfBulkHelper::SfBulkUpsert.upsert(restforce_client, @sfo, df_as_array_of_hashes, batch_size: @batch_size, external_id: @external_id, logger: @logger)
  else
    raise ArgumentError, "Unknown operation: #{@operation}"
  end

  true
end