Class: Salesforce::Bulk::UpsertJob

Inherits:
Job
  • Object
show all
Defined in:
lib/salesforce/bulk/upsert_job.rb

Instance Attribute Summary collapse

Attributes inherited from Job

#batches, #columns, #concurrency_mode, #content_type, #id, #number_batches_completed, #number_batches_failed, #number_batches_in_progress, #number_batches_total, #number_of_batches_queued, #number_records_processed, #number_retries, #object, #object_type, #operation, #state

Instance Method Summary collapse

Methods inherited from Job

#batch, #completed?, #parallel!, #process!, #results, #serial!

Methods included from Attributes

#assign_attributes!

Constructor Details

#initialize(object_type, external_id_col, columns = :all) ⇒ UpsertJob

Returns a new instance of UpsertJob.

Raises:



7
8
9
10
11
# File 'lib/salesforce/bulk/upsert_job.rb', line 7

def initialize(object_type, external_id_col, columns = :all)
  super(object_type, 'upsert', columns)
  self.external_id_col = object_type.columns.find { |scol| scol.name == external_id_col.to_s  }
  raise UnrecognizedColumn.new("#{external_id_col} is not a valid column.") unless self.external_id_col
end

Instance Attribute Details

#external_id_colObject

Returns the value of attribute external_id_col.



5
6
7
# File 'lib/salesforce/bulk/upsert_job.rb', line 5

def external_id_col
  @external_id_col
end

Instance Method Details

#create_job_xmlObject



26
27
28
29
30
31
32
33
# File 'lib/salesforce/bulk/upsert_job.rb', line 26

def create_job_xml
  job_xml do |job_info|
    job_info.operation self.operation
    job_info.object self.object
    job_info.externalIdFieldName self.external_id_col.original_name
    job_info.contentType "CSV"
  end
end

#csv_columnsObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/salesforce/bulk/upsert_job.rb', line 13

def csv_columns
  if columns.blank? || columns == :all
    ([self.external_id_col] + object_type.columns.editable).uniq
  else
    cols = columns.map do |col|
      sf_col = object_type.columns.find { |scol| scol.name == col.to_s  }
      raise UnrecognizedColumn.new("#{col} is not a valid column.") unless sf_col
      sf_col
    end
    ([self.external_id_col] + cols).uniq
  end
end