def record_from_hash(data)
      attributes = data.delete('attributes')
      new_record = find_or_materialize(attributes["type"]).new
      data.each do |name, value|
        field = new_record.description['fields'].find do |field|
          key_from_label(field["label"]) == name || field["name"] == name || field["relationshipName"] == name
        end

        # Field not found
        if field == nil
          break
        end

        # If reference/lookup field data was fetched, recursively build the child record and apply
        if value.is_a?(Hash) and field['type'] == 'reference' and field["relationshipName"]
          relation = record_from_hash( value )
          set_value( new_record, field["relationshipName"], relation, 'reference' )

        # Apply the raw value for all other field types
        else
          set_value(new_record, field["name"], value, field["type"]) if field
        end
      end
      new_record
    end
def record_from_hash(data)
      attributes = data.delete('attributes')
      new_record = find_or_materialize(attributes["type"]).new
      data.each do |name, value|
        field = new_record.description['fields'].find do |field|
          key_from_label(field["label"]) == name || field["name"] == name || field["relationshipName"] == name
        end

        # Field not found
        if field == nil
          break
        end

        # If reference/lookup field data was fetched, recursively build the child record and apply
        if value.is_a?(Hash) and field['type'] == 'reference' and field["relationshipName"]
          relation = record_from_hash( value )
          set_value( new_record, field["relationshipName"], relation, 'reference' )

        # Apply the raw value for all other field types
        else
          set_value(new_record, field["name"], value, field["type"]) if field
        end
      end
      new_record
    end
Converts a Hash of object data into a concrete SObject