Module: SfCli::Sf::Data::UpdateRecord

Defined in:
lib/sf_cli/sf/data/update_record.rb

Instance Method Summary collapse

Instance Method Details

#update_record(object_type, record_id: nil, where: nil, values: nil, target_org: nil, api_version: nil) ⇒ String

Update a object record.

Examples:

sf.data.update_record :Account, record_id: 'xxxxxxx', values: {Name: 'New Account Name'}
sf.data.update_record :Hoge__c, where: {Name: 'Jonny B.Good', Country: 'USA'}, values: {Phone: 'xxxxx', bar: 2000}

Parameters:

  • object_type (Symbol, String)

    object type(ex. Account)

  • record_id (String) (defaults to: nil)

    ID of the object

  • where (Hash) (defaults to: nil)

    field values to identify a record

  • values (Hash) (defaults to: nil)

    field values for update

  • target_org (Symbol, String) (defaults to: nil)

    an alias of paticular org, or username can be used

  • api_version (Numeric) (defaults to: nil)

    override the api version used for api requests made by this command

Returns:

  • (String)

    ID of the record updated

See Also:



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/sf_cli/sf/data/update_record.rb', line 20

def update_record(object_type, record_id: nil, where: nil, values: nil, target_org: nil, api_version: nil)
  where_conditions  = field_value_pairs(where)
  field_values      = field_value_pairs(values)
  flags = {
    :"sobject"     => object_type,
    :"record-id"   => record_id,
    :"where"       => (where_conditions.nil? ? nil : %|"#{where_conditions}"|),
    :"values"      => (field_values.nil? ? nil : %|"#{field_values}"|),
    :"target-org"  => target_org,
    :"api-version" => api_version,
  }
  action = __method__.to_s.tr('_', ' ')
  json = exec(action, flags: flags, redirection: :null_stderr)

  json['result']['id']
end