0.0.5 • Published 1 month ago

salesforce-service v0.0.5

Weekly downloads
-
License
ISC
Repository
github
Last release
1 month ago

salesforce-service

Maintainability Rating Security Rating Reliability Rating Duplicated Lines (%) Bugs Code Smells Technical Debt

Introduction

salesforce-service is a wrapper that helps interacting with Salesforce REST and SOAP API easier. This can be very helpful while testing Salesforce application.

Installation

npm install --save-dev salesforce-service

Usages

Configuration file

Configuration file is a json file in which you can store all relevant information for your Salesforce application. Here is a example:

{
  "urls":{
    "testUrl": "https://test.salesforce.com",
    "baseUrl": "https://test.salesforce.com",
    "domain": "your-domain.my.salesforce.com"
  },
  "paths": {
    "soap": "/services/Soap/u/51.0",
    "data": "/services/data/v51.0",
    "query": "/services/data/v51.0/query/?q="
  }
}

Get session information

const SfService = require('salesforce-service').SfService;

const service = new SfService({
  configFile: 'config.json'
})

service.getSessionId({
  username: 'youruser',
  password: 'yourpass',
  token:'yourtoken'
}).then((res) => {
  console.log(res)
})

Run a query

await service.query('your query command');

Deal with records

it('get record successfully', async () => {
    const response = await service.getRecord('123');
    expect(response.data).toEqual('got record');
  });

  it('create record successfully', async () => {
    const data: JSON = JSON.parse('{"field1": "value1"}');
    const response = await service.createRecord('name', data);
    expect(response.data).toEqual('created record');
  });

  it('update record successfully', async () => {
    const data: JSON = JSON.parse('{"field1": "value1"}');
    const response = await service.updateRecord('123', data);
    expect(response.data).toEqual('updated record');
  });

  it('delete record successfully', async () => {
    const response = await service.deleteRecord('123');
    expect(response.data).toEqual('deleted record');
  });