Module: SfCli::Sf::Data::GetRecord

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

Instance Method Summary collapse

Instance Method Details

#get_record(object_type, record_id: nil, where: nil, target_org: nil, model_class: nil) ⇒ Object

get a object record. (eqivalent to sf data get record)

object_type — Object Type (ex. Account)

record_id — id of the object

where — hash object that is used to identify a record

target_org — an alias of paticular org, not default one

model_class — the object model class

sf.data.get_record :Account, record_id: 'xxxxxxx'
sf.data.get_record :Account, where: {Name: 'Jonny B.Good', Country: 'USA'}

CustomObject = Struct.new(:Id, :Name)
sf.data.get_record :TheCustomObject__c, record_id: 'xxxxx', model_class: CustomObject  # returns a CustomObject instance

For more command details, see the command reference



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/sf_cli/sf/data/get_record.rb', line 25

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

  result = json['result']
  result.delete 'attributes'

  model_class ? model_class.new(**result) : result
end