{"id":21638086,"url":"https://github.com/purecloudlabs/sobject","last_synced_at":"2025-04-11T16:42:30.470Z","repository":{"id":57364961,"uuid":"86529417","full_name":"purecloudlabs/sobject","owner":"purecloudlabs","description":null,"archived":false,"fork":false,"pushed_at":"2025-01-03T06:34:06.000Z","size":73,"stargazers_count":1,"open_issues_count":0,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-10T19:09:32.853Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/purecloudlabs.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-03-29T02:28:01.000Z","updated_at":"2025-01-03T06:34:10.000Z","dependencies_parsed_at":"2024-11-25T09:04:04.074Z","dependency_job_id":null,"html_url":"https://github.com/purecloudlabs/sobject","commit_stats":null,"previous_names":["mypurecloud/sobject"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purecloudlabs%2Fsobject","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purecloudlabs%2Fsobject/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purecloudlabs%2Fsobject/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purecloudlabs%2Fsobject/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/purecloudlabs","download_url":"https://codeload.github.com/purecloudlabs/sobject/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248442323,"owners_count":21104158,"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":[],"created_at":"2024-11-25T04:08:08.525Z","updated_at":"2025-04-11T16:42:30.422Z","avatar_url":"https://github.com/purecloudlabs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SalesForce SObject\n\nAllows queries and CRUD operations to be performed on a SalesForce SObject with minimal setup and a friendly API.\n\nSimply give it the SObject's name (e.g. `'Account'`) and an object which defines friendly names for the properties in which you're interested (e.g. `{ primaryContactName: 'Primary_Contact__r.Name' }`). **Now you can query and update records using the friendly names, and this class takes care of the conversion to and from the SalesForce format.**\n\n## Basic Usage\n\nEither extend `SObject` to override its `objectName` and `propertyMap` properties, or simply create an instance by passing those properties into this class's constructor. Either approach will allow you to use the default implementations of the CRUD methods (e.g. `query()`, `insert()`, etc.) which automatically handle the property name conversion.\n\n```js\n// AccountStorage.js: This shows how you extend SObject for your various objects. Keeping these declarations\n//                    in separate files is a good idea if you're working with many different objects.\n\nimport SObject from 'sobject';\n\nexport default class AccountStorage extends SObject {\n\n    get objectName() {\n        return 'Account';\n    }\n\n    get propertyMap() {\n        return {\n            id: 'Id',\n            name: 'Name',\n            primaryContactId: 'Primary_Contact__c'\n            primaryContactEmail: 'Primary_Contact__r.Email'\n        };\n    }\n}\n```\n\n\n```js\n// index.js\nimport { SObject, SalesForceConnection } from 'sobject';\nimport AccountStorage from './AccountStorage';\n\n// Create a connection, which handles sending authenticated requests to the API.\nlet connection = new SalesForceConnection({\n\n    loginUrl: 'https://test.salesforce.com/services/oauth2/token',\n    clientId: '3MVG9lKcPoNINVBJSoQsNCD.HHDdbugPsNXwwyFbgb47KWa_PTv',\n    clientSecret: '5678471853609579508',\n    username: 'steve.stevens@example.com',\n    password: 'I❤️SalesForce'\n});\n\n// Instantiate the class we created for handling Account objects.\nlet accountStorage = new AccountStorage({ connection });\n\n// We can also just create an SObject by passing its constructor those `objectName` and `propertyMap`\n// properties. This is handy for simple scripting.\nlet contactStorage = new SObject({\n    connection,\n    objectName: 'Contact',\n    propertyMap: {\n        id: 'Id',\n        accountId: 'AccountId',\n        firstName: 'FirstName',\n        lastName: 'LastName',\n        email: 'Email'\n    }\n});\n\nlet accountId;\n\n// Get a specific account by name\naccountStorage.get({ name: 'Goofy Roofers' })\n.then(account =\u003e {\n\n    accountId = account.id;\n\n    // Insert a new contact for the account\n    return contactStorage.insert({\n        accountId,\n        firstName: 'Jimothy',\n        last: 'Bagelson',\n        email: 'jimothy.bagelson@example.com'\n    });\n})\n.then(contact =\u003e {\n    // Set the account's custom field using the new contact.\n    return accountStorage.update({ id: accountId, primaryContactId: contact.id });\n})\n.then(() =\u003e {\n    // Get the account again, this time querying by a field on its nested contact object.\n    return accountStorage.query({ primaryContactEmail: 'jimothy.bagelson@example.com' });\n})\n.then(account =\u003e {\n    // Delete the contact we had created.\n    return Promise.all([\n        contactStorage.delete({ id: account.primaryContactId }),\n        accountStorage.update({ id: accountId, primaryContactId: null })\n    ]);\n});\n```\n\nFor more detailed information, check out [this module's API docs](https://github.com/MyPureCloud/sobject/blob/master/docs/api.md) and the [SalesForce documentation on setting up REST API authorization](https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/quickstart_oauth.htm).\n\n## Development\n\nThis module is written in ES2015, but is currently transpiled to ES5 for distribution.\n\n### Building\n\n```\nnpm run build\n```\n\nThere's also a git pre-commit hook which automatically transpiles and regenerates the docs upon commit.\n\n### Testing\n\n```\nnpm test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpurecloudlabs%2Fsobject","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpurecloudlabs%2Fsobject","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpurecloudlabs%2Fsobject/lists"}