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) ⇒ Hash, Class

Get a object record.

Examples:

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)
obj = sf.data.get_record :TheCustomObject__c, record_id: 'xxxxx', model_class: CustomObject # returns a CustomObject instance
obj.Name # Name field of the record

Parameters:

  • object_type (Symbol, String)

    object type(ex. Account)

  • record_id (String) (defaults to: nil)

    id of the object

  • where (Hash) (defaults to: nil)

    conditions to identify a record

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

    an alias of paticular org, not default one

  • model_class (Class) (defaults to: nil)

    the object model class

Returns:

  • (Hash, Class)

    if proper model class is specified, the return value is the instance of the class. Otherwise, it’s a Hash object.

See Also:



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

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