Class: Remi::DataTarget::Salesforce

Inherits:
Remi::DataSubject show all
Includes:
Remi::DataSubject::DataTarget, 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 included from Remi::DataSubject::DataTarget

#load

Methods inherited from Remi::DataSubject

#df, #df=, #field_symbolizer

Constructor Details

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

Returns a new instance of Salesforce.



99
100
101
102
# File 'lib/remi/data_subject/salesforce.rb', line 99

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



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

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