Module: SoqlObjectDescribe
- Included in:
- SoqlData
- Defined in:
- lib/leap_salesforce/soql_data/soql_object_describe.rb
Overview
Methods relating to describing a soql object See developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_sobject_describe.htm for reference. Note the data here is cached. If metadata changes you would need to re run Ruby Code to get updates if a call has already been made
Instance Method Summary collapse
-
#accessors ⇒ Hash
List of accessors for an object and what they relate to.
- #changes_from_date(_date) ⇒ Object
-
#default_for(field_name) ⇒ String?
Default value for field provided.
-
#description ⇒ SoqlData
Retrieve JSON that describes current object.
-
#field_names ⇒ Array
Field values for field names.
-
#fields ⇒ Array
List of fields that each are a hash of attributes.
-
#label_names ⇒ Array
Label names of object.
- #layouts ⇒ Object
- #layouts_for(record_type_id) ⇒ Object
-
#length_for(field_name) ⇒ Integer
Max length of field.
-
#picklist_for(field_name) ⇒ Array
Finding Picklist values for specified fields.
-
#picklists ⇒ Array
List of labels that have picklists.
-
#properties_for(field_name) ⇒ Hash
Hash storing all properties of a field.
-
#relationship_name_for(field_name) ⇒ String?
Other entity this field relates to if it’s a reference field.
- #required ⇒ Object
-
#type_for(field_name) ⇒ String
Type of field (e.g., picklist, string, double, reference).
Instance Method Details
#accessors ⇒ Hash
Returns List of accessors for an object and what they relate to.
103 104 105 106 107 108 109 110 111 |
# File 'lib/leap_salesforce/soql_data/soql_object_describe.rb', line 103 def accessors return @attr_hash if @attr_hash @attr_hash = {} fields.each do |field| @attr_hash[field['label'].unused_ruby_name.to_sym] = important_attributes_for(field) end @attr_hash end |
#changes_from_date(_date) ⇒ Object
Get this to work
11 12 13 14 |
# File 'lib/leap_salesforce/soql_data/soql_object_describe.rb', line 11 def changes_from_date(_date) @changes_from_date ||= new("describe #{self}", method: :get, suburl: "sobjects/#{soql_object_name}/describe/", params: { if_modified_since: 'Wed, 3 Jul 2013 19:43:31 GMT' }) end |
#default_for(field_name) ⇒ String?
Returns Default value for field provided.
66 67 68 |
# File 'lib/leap_salesforce/soql_data/soql_object_describe.rb', line 66 def default_for(field_name) properties_for(field_name)['defaultValue'] end |
#description ⇒ SoqlData
Returns Retrieve JSON that describes current object.
17 18 19 |
# File 'lib/leap_salesforce/soql_data/soql_object_describe.rb', line 17 def description @description ||= new("describe #{self}", method: :get, suburl: "sobjects/#{soql_object_name}/describe/") end |
#field_names ⇒ Array
Field values for field names
98 99 100 |
# File 'lib/leap_salesforce/soql_data/soql_object_describe.rb', line 98 def field_names fields.collect { |field| field['name'] } end |
#fields ⇒ Array
Returns List of fields that each are a hash of attributes.
32 33 34 |
# File 'lib/leap_salesforce/soql_data/soql_object_describe.rb', line 32 def fields @fields ||= description[:fields] end |
#label_names ⇒ Array
Returns Label names of object.
92 93 94 |
# File 'lib/leap_salesforce/soql_data/soql_object_describe.rb', line 92 def label_names fields.collect { |field| field['label'] } end |
#layouts ⇒ Object
21 22 23 24 |
# File 'lib/leap_salesforce/soql_data/soql_object_describe.rb', line 21 def layouts @layouts ||= new("layouts for #{self}", method: :get, suburl: "sobjects/#{soql_object_name}/describe/layouts") end |
#layouts_for(record_type_id) ⇒ Object
26 27 28 29 |
# File 'lib/leap_salesforce/soql_data/soql_object_describe.rb', line 26 def layouts_for(record_type_id) new("layouts for #{self} on #{record_type_id}", method: :get, suburl: "sobjects/#{soql_object_name}/describe/layouts/#{record_type_id}") end |
#length_for(field_name) ⇒ Integer
Returns Max length of field.
60 61 62 |
# File 'lib/leap_salesforce/soql_data/soql_object_describe.rb', line 60 def length_for(field_name) properties_for(field_name)['length'] end |
#picklist_for(field_name) ⇒ Array
Finding Picklist values for specified fields
52 53 54 55 56 |
# File 'lib/leap_salesforce/soql_data/soql_object_describe.rb', line 52 def picklist_for(field_name) properties = properties_for field_name properties['picklistValues'].collect { |list| list['label'] }.compact end |
#picklists ⇒ Array
Returns List of labels that have picklists.
75 76 77 |
# File 'lib/leap_salesforce/soql_data/soql_object_describe.rb', line 75 def picklists label_names.find_all { |f| type_for(f) == 'picklist' } end |
#properties_for(field_name) ⇒ Hash
Returns Hash storing all properties of a field.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/leap_salesforce/soql_data/soql_object_describe.rb', line 38 def properties_for(field_name) field_name = field_name.to_s properties = fields.find { |field| %w[name label].any? { |label| field[label] == field_name } } unless properties raise LeapSalesforce::ResponseError, "Field name '#{field_name}' not found in '#{self}'" \ " using table name '#{soql_object_name}'. Field names are #{field_names}" end properties end |
#relationship_name_for(field_name) ⇒ String?
Returns Other entity this field relates to if it’s a reference field.
87 88 89 |
# File 'lib/leap_salesforce/soql_data/soql_object_describe.rb', line 87 def relationship_name_for(field_name) properties_for(field_name)['relationshipName'] end |
#required ⇒ Object
70 71 72 |
# File 'lib/leap_salesforce/soql_data/soql_object_describe.rb', line 70 def required fields.find_all { |field| field[''] } end |
#type_for(field_name) ⇒ String
Returns Type of field (e.g., picklist, string, double, reference).
81 82 83 |
# File 'lib/leap_salesforce/soql_data/soql_object_describe.rb', line 81 def type_for(field_name) properties_for(field_name)['type'] end |