Module: SalesforceRecord::Persistence::ClassMethods
- Defined in:
- lib/salesforce_record/persistence.rb
Instance Method Summary collapse
-
#create(attributes) ⇒ Object
Tries to create an instance, given a set of attributes.
- #encode_attributes(attributes) ⇒ Object
Instance Method Details
#create(attributes) ⇒ Object
Tries to create an instance, given a set of attributes
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/salesforce_record/persistence.rb', line 45 def create(attributes) fields = encode_attributes(attributes).merge(:type => self.salesforce_table_name.to_s) # Tries to create it remotely begin id = self.salesforce_adapter.create( self.salesforce_table_name, fields ) # If successful, return an instance with the given Id return from_salesforce(fields.merge(:Id => id)) # TODO : have a real handling of failures rescue => e puts e. return nil end end |
#encode_attributes(attributes) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/salesforce_record/persistence.rb', line 65 def encode_attributes(attributes) {}.tap do |encoded_attributes| attributes.each do |name, value| if (field = self.get_field(name)) encoded_attributes[name] = field.encode value else encoded_attributes[name] = value end end end end |