{"id":13879717,"url":"https://github.com/NestAway/salesforce-orm","last_synced_at":"2025-07-16T15:32:56.987Z","repository":{"id":56894195,"uuid":"93631131","full_name":"NestAway/salesforce-orm","owner":"NestAway","description":"Active record like ORM for Salesforce","archived":false,"fork":false,"pushed_at":"2019-04-07T14:01:45.000Z","size":41,"stargazers_count":8,"open_issues_count":5,"forks_count":7,"subscribers_count":56,"default_branch":"master","last_synced_at":"2024-11-16T10:31:02.052Z","etag":null,"topics":["activerecord","gem","orm","rails","ruby","salesforce"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NestAway.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-07T12:07:57.000Z","updated_at":"2020-10-31T19:48:43.000Z","dependencies_parsed_at":"2022-08-21T01:20:23.876Z","dependency_job_id":null,"html_url":"https://github.com/NestAway/salesforce-orm","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NestAway%2Fsalesforce-orm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NestAway%2Fsalesforce-orm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NestAway%2Fsalesforce-orm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NestAway%2Fsalesforce-orm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NestAway","download_url":"https://codeload.github.com/NestAway/salesforce-orm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226143895,"owners_count":17580245,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["activerecord","gem","orm","rails","ruby","salesforce"],"created_at":"2024-08-06T08:02:30.139Z","updated_at":"2024-11-24T08:31:41.043Z","avatar_url":"https://github.com/NestAway.png","language":"Ruby","readme":"# salesforce-orm\nActive record like ORM for Salesforce\n\n[![Build Status](https://travis-ci.org/NestAway/salesforce-orm.svg?branch=master)](https://travis-ci.org/NestAway/salesforce-orm)\n\n## Setup\n\nAdd gem to your Gemfile\n\n```\ngem 'salesforce-orm'\n```\n\nOr, If you want to install globally\n\n```\ngem install salesforce-orm\n```\n\nThis Gem internally use [Restforce](https://github.com/ejholmes/restforce), So you have to configure it\n\nThere are 2 options to configure ([Restforce config](https://github.com/ejholmes/restforce#initialization))\n\n**Option 1**\n\nSet ENV variable as per Restforce doc\n\n**Option 2**\n\nIn rails, write below code in application.rb or environment specific file\n\nOther projects, run it before you use SaleforceOrm\n\n```ruby\n  SaleforceOrm::Configuration.restforce_config = {\n    ... # Restforce configuration\n  }\n```\n\n## Usage\n\nCreate object class\n\n```ruby\nclass SampleObject \u003c SalesforceOrm::ObjectBase\nend\n```\n\n### object_name\n\nDefault object name is `class.name`\n\n```ruby\nSampleObject\n```\n\nIf you have a custom object name,\n\n```ruby\nclass SampleObject \u003c SalesforceOrm::ObjectBase\n  self.object_name = 'SampleObject__c'\nend\n```\n\n### field_map\n\nField map is used for create, update actions. This can be used for aliasing the field names\n\nDefault field map for `SampleObject`\n\n```ruby\n  {\n    id: :Id,\n    created_at: :CreatedAt,\n    updated_at: :UpdatedAt\n  }\n```\n\nIf you wanna map more fields for an object\n\n```ruby\nclass SampleObject \u003c SalesforceOrm::ObjectBase\n  self.field_map = {\n    field_one: :FieldOne,\n    field_two: :FieldTwo__c,\n  }\nend\n```\n\n### data_type_map\n\nAllowed data types are,\n\n- `:integer`\n- `:float`\n- `:date_time`\n- `:date`\n- `:array`\n- `:boolean`\n\nDefault is same data type of given value\n\nDefault data type map for `SampleObject`\n\n```ruby\n  {\n    created_at: :datetime,\n    updated_at: :datetime\n  }\n```\n\nIf you wanna change the data type of some fields\n\n```ruby\nclass SampleObject \u003c SalesforceOrm::ObjectBase\n  self.data_type_map = {\n    field_one: :datetime,\n    field_two: :integer\n  }\nend\n```\n\n**NOTE: It's mandatory to add data type map for boolean fields**\n\n### record_type\n\nBy default there is no record type configured for any object\n\nTo specify a record type,\n\n```ruby\nclass SampleObject \u003c SalesforceOrm::ObjectBase\n  self.record_type = 'Xyz' # DeveloperName in RecordType object\nend\n```\n\nAll the queries and `create!` method will automatically use record type\n\nFirst time use the object, we make a call to Salesforce and find the record type by it's `DeveloperName`. This will be cached in memory.\n\nWith Rails in except in development or test env, we take the advantage of `Rails.cache`\n\n### Methods\n\nMethods are similar to ActiveRecord::Base\n\nClass methods\n\n```ruby\nSampleObject.[\n  :create!,\n  :update_all!,\n  :destroy_all!,\n  :where,\n  :select,\n  :except,\n  :group,\n  :order,\n  :reorder,\n  :limit,\n  :offset,\n  :first,\n  :last,\n  :each,\n  :scoped,\n  :all,\n  :find_by_*\n]\n```\n\neg:\n```ruby\nSampleObject.where(id: 'qd')\n\nSampleObject.where(id: ['eqd', 'qqwd'])\n\nSampleObject.where(id: ['eqd', 'qqwd'], field_one: 'KJbn').where('a = b').all\n\nSampleObject.where(id: 'qd').group(:a, :b).each do |sobj|\n  puts sobj.id\nend\n\nSampleObject.find('qwd')\n\nSampleObject.find_by_id('qwd')\n\nSampleObject.find_by_field_one_and_field_two_and_field_three(1, 2, 3)\n\nSampleObject.select('count(id)').all\n```\n\n**NOTE: Salesforce API's accepts SOQL query as a URL params, so make sure URL length is not longer than 16087 chars**\n\nInstance methods\n\n```ruby\nSampleObject.[\n  :update_attributes,\n  :destroy\n]\n```\n\nOther class methods (Specific to SalesforceOrm)\n\n#### update_by_id!\n\nTo update an object by id\n\n```ruby\nSampleObject.update_by_id!('some_id', {feild_one: 'some_value', field_two: 'some_other_value'})\n```\n\n#### destroy_by_id!\n\nTo destroy an object by id\n\n```ruby\nSampleObject.destroy_by_id!('some_id')\n```\n\n#### to_soql\n\nTo generate, SOQL query (Equavalent to `to_sql`)\n\n#### build\n\nTo create a new instance of SampleObject\n\n```ruby\nSampleObject.build({id: 'some id', field_one: 'Some value'})\n```\n\n## Pending\n\n- Default values\n- Relationships\n- More data types\n- Better aggregate methods\n\n## Contributing\n\nIf you'd like to contribute a feature or bugfix: Thanks! To make sure your\nfix/feature has a high chance of being included, please read the following\nguidelines:\n\n1. Post a [pull request](https://github.com/NestAway/salesforce-orm/compare).\n2. Make sure there are tests! We will not accept any patch that is not tested.\n   It's a rare time when explicit tests aren't needed. If you have questions\n   about writing tests for salesforce-orm, please open a\n   [GitHub issue](https://github.com/NestAway/salesforce-orm/issues/new).\n\nThank you to all [the contributors](https://github.com/NestAway/salesforce-orm/graphs/contributors)!\n","funding_links":[],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNestAway%2Fsalesforce-orm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FNestAway%2Fsalesforce-orm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNestAway%2Fsalesforce-orm/lists"}