diff --git a/packages/nodes-base/nodes/Salesforce/Salesforce.node.ts b/packages/nodes-base/nodes/Salesforce/Salesforce.node.ts index 1e01664012..6ccb8676d2 100644 --- a/packages/nodes-base/nodes/Salesforce/Salesforce.node.ts +++ b/packages/nodes-base/nodes/Salesforce/Salesforce.node.ts @@ -71,7 +71,13 @@ import { import { ITask, } from './TaskInterface'; - +import { + userFields, + userOperations, +} from './UserDescription'; +import { + IUser, +} from './UserInterface'; export class Salesforce implements INodeType { description: INodeTypeDescription = { @@ -135,7 +141,11 @@ export class Salesforce implements INodeType { value: 'task', description: 'Represents a business activity such as making a phone call or other to-do items. In the user interface, and records are collectively referred to as activities.', }, - + { + name: 'User', + value: 'user', + description: 'Represents a person, which is one user in system.', + }, ], default: 'lead', description: 'Resource to consume.', @@ -154,6 +164,8 @@ export class Salesforce implements INodeType { ...taskFields, ...attachmentOperations, ...attachmentFields, + ...userOperations, + ...userFields, ], }; @@ -1885,6 +1897,35 @@ export class Salesforce implements INodeType { responseData = await salesforceApiRequest.call(this, 'GET', '/sobjects/attachment'); } } + if (resource === 'user') { + //https://developer.salesforce.com/docs/api-explorer/sobject/User/get-user-id + if (operation === 'get') { + const userId = this.getNodeParameter('userId', i) as string; + responseData = await salesforceApiRequest.call(this, 'GET', `/sobjects/user/${userId}`); + } + //https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_query.htm + if (operation === 'getAll') { + const returnAll = this.getNodeParameter('returnAll', i) as boolean; + const options = this.getNodeParameter('options', i) as IDataObject; + const fields = ['id,name,email']; + if (options.fields) { + // @ts-ignore + fields.push(...options.fields.split(',')); + } + try { + if (returnAll) { + qs.q = `SELECT ${fields.join(',')} FROM User`; + responseData = await salesforceApiRequestAllItems.call(this, 'records', 'GET', '/query', {}, qs); + } else { + const limit = this.getNodeParameter('limit', i) as number; + qs.q = `SELECT ${fields.join(',')} FROM User Limit ${limit}`; + responseData = await salesforceApiRequestAllItems.call(this, 'records', 'GET', '/query', {}, qs); + } + } catch(err) { + throw new Error(`Salesforce Error: ${err}`); + } + } + } if (Array.isArray(responseData)) { returnData.push.apply(returnData, responseData as IDataObject[]); } else { diff --git a/packages/nodes-base/nodes/Salesforce/UserDescription.ts b/packages/nodes-base/nodes/Salesforce/UserDescription.ts new file mode 100644 index 0000000000..2bc9089f9a --- /dev/null +++ b/packages/nodes-base/nodes/Salesforce/UserDescription.ts @@ -0,0 +1,126 @@ +import { + INodeProperties, +} from 'n8n-workflow'; + +export const userOperations = [ + { + displayName: 'Operation', + name: 'operation', + type: 'options', + displayOptions: { + show: { + resource: [ + 'user', + ], + }, + }, + options: [ + { + name: 'Get', + value: 'get', + description: 'Get a user', + }, + { + name: 'Get All', + value: 'getAll', + description: 'Get all users', + }, + ], + default: 'get', + description: 'The operation to perform.' + } +] as INodeProperties[]; + +export const userFields = [ + /* -------------------------------------------------------------------------- */ + /* user:get */ + /* -------------------------------------------------------------------------- */ + { + displayName: 'User ID', + name: 'userId', + type: 'string', + required: true, + default: '', + displayOptions: { + show: { + resource: [ + 'user', + ], + operation: [ + 'get', + ], + }, + }, + description: 'Id of user that needs to be fetched' + }, + /* -------------------------------------------------------------------------- */ + /* user:getAll */ + /* -------------------------------------------------------------------------- */ + { + displayName: 'Return All', + name: 'returnAll', + type: 'boolean', + displayOptions: { + show: { + resource: [ + 'user', + ], + operation: [ + 'getAll', + ], + } + }, + default: false, + description: 'If all results should be returned or only up to a given limit.' + }, + { + displayName: 'Limit', + name: 'limit', + type: 'number', + displayOptions: { + show: { + resource: [ + 'user', + ], + operation: [ + 'getAll', + ], + returnAll: [ + false, + ], + }, + }, + typeOptions: { + minValue: 1, + maxValue: 100 + }, + default: 50, + description: 'How many results to return.' + }, + { + displayName: 'Options', + name: 'options', + type: 'collection', + placeholder: 'Add Field', + default: {}, + displayOptions: { + show: { + resource: [ + 'user', + ], + operation: [ + 'getAll', + ], + }, + }, + options: [ + { + displayName: 'Fields', + name: 'fields', + type: 'string', + default: '', + description: 'Fields to include separated by ,' + }, + ], + }, +] as INodeProperties[]; diff --git a/packages/nodes-base/nodes/Salesforce/UserInterface.ts b/packages/nodes-base/nodes/Salesforce/UserInterface.ts new file mode 100644 index 0000000000..035a1b6c9f --- /dev/null +++ b/packages/nodes-base/nodes/Salesforce/UserInterface.ts @@ -0,0 +1,10 @@ +export interface IUser { + Alias?: string; + Department?: string; + Division?: string; + Email?: string; + IsActive?: boolean; + MobilePhone?: string; + Title?: string; + Username?: string; +}