Module: SfCli::Sf::Data::CreateRecord

Included in:
Core
Defined in:
lib/sf_cli/sf/data/create_record.rb

Instance Method Summary collapse

Instance Method Details

#create_record(object_type, values: {}, target_org: nil) ⇒ Object

create a object record.

object_type — Object Type (ex. Account)

values — field values to be assigned

target_org — an alias of paticular org, or username can be used

# create a TheCustomObject record with name and age
sf.data.create_record :TheCustomObject__c, values: {Name: "John Smith", Age: 33}

For more command details, see the command reference



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/sf_cli/sf/data/create_record.rb', line 17

def create_record(object_type, values: {}, target_org: nil)
  field_values = field_value_pairs(values)
  flags = {
    :"sobject"    => object_type,
    :"values"      => (field_values.nil? ? nil : %|"#{field_values}"|),
    :"target-org" => target_org,
  }
  action = __method__.to_s.tr('_', ' ')
  json = exec(action, flags: flags, redirection: :null_stderr)

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