Class: Remi::Loader::SalesforceSoap

Inherits:
Remi::Loader show all
Includes:
DataSubject::SalesforceSoap
Defined in:
lib/remi/data_subjects/salesforce_soap.rb

Overview

Salesforce SOAP loader The Salesforce SOAP loader can be used to merge salesforce objects (for those objects that support the merge operation). To do so, each row of the dataframe must contain a field called :Id that references the master record that survives the merge operation. It must also contain a :Merge_Id field that specifies the salesforce Id of the record that is to be merged into the master. Other fields may also be specified that will be used to update the master record.

Examples:

class MyJob < Remi::Job
  target :merge_contacts do
    encoder Remi::Encoder::SalesforceSoap.new
    loader Remi::Loader::SalesforceSoap.new(
      credentials: { },
      object: :Contact,
      operation: :merge,
      merge_id_field: :Merge_Id
    )
  end
end

job = MyJob.new
job.merge_contacts.df = Remi::DataFrame::Daru.new({ Id: ['003g000001IX4HcAAL'], Note__c: ['Cheeseburger in Paradise'], Merge_Id: ['003g000001LE7dXAAT']})
job.merge_contacts.load

Instance Attribute Summary

Attributes inherited from Remi::Loader

#context, #logger

Instance Method Summary collapse

Methods included from DataSubject::SalesforceSoap

#soapforce_client

Methods inherited from Remi::Loader

#autoload, #fields

Constructor Details

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

Returns a new instance of SalesforceSoap.

Parameters:

  • credentials (Hash)

    Used to authenticate with salesforce

  • object (Symbol)

    Salesforce object to extract

  • operation (Symbol)

    Salesforce operation to perform (:merge) <- Merge is the only operation currently supported

  • merge_id_field (Symbol)

    For merge operations, this is the name of the field containing the id of the record to be merged (default: :Merge_Id)



65
66
67
68
# File 'lib/remi/data_subjects/salesforce_soap.rb', line 65

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

Instance Method Details

#load(data) ⇒ true

Returns On success.

Parameters:

  • data (Encoder::Salesforce)

    Data that has been encoded appropriately to be loaded into the target

Returns:

  • (true)

    On success



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/remi/data_subjects/salesforce_soap.rb', line 72

def load(data)
  logger.info "Performing Salesforce Soap #{@operation} on object #{@sfo}"
  if @operation == :merge
    # The Soapforce gem only supports one slow-ass merge at a time :(
    data.each do |row|
      unless row.include?(@merge_id_field)
        raise KeyError, "Merge id field not found: #{@merge_id_field}"
      end

      merge_id = Array(row.delete(@merge_id_field))
      soapforce_client.merge(@sfo, row, merge_id)
    end
  else
    raise ArgumentError, "Unknown soap operation: #{@operation}"
  end
end