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, api_version: nil) ⇒ String

create a object record.

Examples:

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

Parameters:

  • object_type (Symbol, String)

    object type(ex. Account)

  • values (Hash) (defaults to: {})

    field values to be assigned

  • 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)

    record ID

See Also:



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

def create_record(object_type, values: {}, target_org: nil, api_version: nil)
  field_values = field_value_pairs(values)
  flags = {
    :"sobject"    => object_type,
    :"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