UNPKG

n8n-nodes-base

Version:

Base nodes of n8n

1,000 lines 151 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Salesforce = void 0; const n8n_workflow_1 = require("n8n-workflow"); const AccountDescription_1 = require("./AccountDescription"); const AttachmentDescription_1 = require("./AttachmentDescription"); const CaseDescription_1 = require("./CaseDescription"); const ContactDescription_1 = require("./ContactDescription"); const CustomObjectDescription_1 = require("./CustomObjectDescription"); const DocumentDescription_1 = require("./DocumentDescription"); const FlowDescription_1 = require("./FlowDescription"); const GenericFunctions_1 = require("./GenericFunctions"); const LeadDescription_1 = require("./LeadDescription"); const OpportunityDescription_1 = require("./OpportunityDescription"); const SearchDescription_1 = require("./SearchDescription"); const TaskDescription_1 = require("./TaskDescription"); const UserDescription_1 = require("./UserDescription"); class Salesforce { description = { displayName: 'Salesforce', name: 'salesforce', icon: 'file:salesforce.svg', group: ['output'], version: 1, subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}', description: 'Consume Salesforce API', defaults: { name: 'Salesforce', }, usableAsTool: true, inputs: [n8n_workflow_1.NodeConnectionTypes.Main], outputs: [n8n_workflow_1.NodeConnectionTypes.Main], credentials: [ { name: 'salesforceOAuth2Api', required: true, displayOptions: { show: { authentication: ['oAuth2'], }, }, }, { name: 'salesforceJwtApi', required: true, displayOptions: { show: { authentication: ['jwt'], }, }, }, ], properties: [ { displayName: 'Authentication', name: 'authentication', type: 'options', options: [ { name: 'OAuth2', value: 'oAuth2', }, { name: 'OAuth2 JWT', value: 'jwt', }, ], default: 'oAuth2', description: 'OAuth Authorization Flow', }, { displayName: 'Resource', name: 'resource', type: 'options', noDataExpression: true, options: [ { name: 'Account', value: 'account', description: 'Represents an individual account, which is an organization or person involved with your business (such as customers, competitors, and partners)', }, { name: 'Attachment', value: 'attachment', description: 'Represents a file that a has uploaded and attached to a parent object', }, { name: 'Case', value: 'case', description: 'Represents a case, which is a customer issue or problem', }, { name: 'Contact', value: 'contact', description: 'Represents a contact, which is an individual associated with an account', }, { name: 'Custom Object', value: 'customObject', description: 'Represents a custom object', }, { name: 'Document', value: 'document', description: 'Represents a document', }, { name: 'Flow', value: 'flow', description: 'Represents an autolaunched flow', }, { name: 'Lead', value: 'lead', description: 'Represents a prospect or potential', }, { name: 'Opportunity', value: 'opportunity', description: 'Represents an opportunity, which is a sale or pending deal', }, { name: 'Search', value: 'search', description: 'Search records', }, { name: 'Task', 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', }, ...LeadDescription_1.leadOperations, ...LeadDescription_1.leadFields, ...ContactDescription_1.contactOperations, ...ContactDescription_1.contactFields, ...CustomObjectDescription_1.customObjectOperations, ...CustomObjectDescription_1.customObjectFields, ...DocumentDescription_1.documentOperations, ...DocumentDescription_1.documentFields, ...OpportunityDescription_1.opportunityOperations, ...OpportunityDescription_1.opportunityFields, ...AccountDescription_1.accountOperations, ...AccountDescription_1.accountFields, ...SearchDescription_1.searchOperations, ...SearchDescription_1.searchFields, ...CaseDescription_1.caseOperations, ...CaseDescription_1.caseFields, ...TaskDescription_1.taskOperations, ...TaskDescription_1.taskFields, ...AttachmentDescription_1.attachmentOperations, ...AttachmentDescription_1.attachmentFields, ...UserDescription_1.userOperations, ...UserDescription_1.userFields, ...FlowDescription_1.flowOperations, ...FlowDescription_1.flowFields, ], }; methods = { loadOptions: { // Get all the lead statuses to display them to user so that they can // select them easily async getLeadStatuses() { const returnData = []; const qs = { q: 'SELECT id, MasterLabel FROM LeadStatus', }; const statuses = await GenericFunctions_1.salesforceApiRequestAllItems.call(this, 'records', 'GET', '/query', {}, qs); for (const status of statuses) { const statusName = status.MasterLabel; returnData.push({ name: statusName, value: statusName, }); } (0, GenericFunctions_1.sortOptions)(returnData); return returnData; }, // Get all the users to display them to user so that they can // select them easily async getUsers() { const returnData = []; const qs = { q: 'SELECT id, Name FROM User', }; const users = await GenericFunctions_1.salesforceApiRequestAllItems.call(this, 'records', 'GET', '/query', {}, qs); for (const user of users) { const userName = user.Name; const userId = user.Id; returnData.push({ name: userName, value: userId, }); } (0, GenericFunctions_1.sortOptions)(returnData); return returnData; }, // Get all the users and case queues to display them to user so that they can // select them easily async getCaseOwners() { const returnData = []; const qsQueues = { q: "SELECT Queue.Id, Queue.Name FROM QueuesObject where Queue.Type='Queue' and SobjectType = 'Case'", }; const queues = await GenericFunctions_1.salesforceApiRequestAllItems.call(this, 'records', 'GET', '/query', {}, qsQueues); for (const queue of queues) { const queueName = queue.Queue.Name; const queueId = queue.Queue.Id; returnData.push({ name: `Queue: ${queueName}`, value: queueId, }); } const qsUsers = { q: 'SELECT id, Name FROM User', }; const users = await GenericFunctions_1.salesforceApiRequestAllItems.call(this, 'records', 'GET', '/query', {}, qsUsers); const userPrefix = returnData.length > 0 ? 'User: ' : ''; for (const user of users) { const userName = user.Name; const userId = user.Id; returnData.push({ name: userPrefix + userName, value: userId, }); } (0, GenericFunctions_1.sortOptions)(returnData); return returnData; }, // Get all the users and lead queues to display them to user so that they can // select them easily async getLeadOwners() { const returnData = []; const qsQueues = { q: "SELECT Queue.Id, Queue.Name FROM QueuesObject where Queue.Type='Queue' and SobjectType = 'Lead'", }; const queues = await GenericFunctions_1.salesforceApiRequestAllItems.call(this, 'records', 'GET', '/query', {}, qsQueues); for (const queue of queues) { const queueName = queue.Queue.Name; const queueId = queue.Queue.Id; returnData.push({ name: `Queue: ${queueName}`, value: queueId, }); } const qsUsers = { q: 'SELECT id, Name FROM User', }; const users = await GenericFunctions_1.salesforceApiRequestAllItems.call(this, 'records', 'GET', '/query', {}, qsUsers); const userPrefix = returnData.length > 0 ? 'User: ' : ''; for (const user of users) { const userName = user.Name; const userId = user.Id; returnData.push({ name: userPrefix + userName, value: userId, }); } (0, GenericFunctions_1.sortOptions)(returnData); return returnData; }, // Get all the lead sources to display them to user so that they can // select them easily async getLeadSources() { const returnData = []; // TODO: find a way to filter this object to get just the lead sources instead of the whole object const { fields } = await GenericFunctions_1.salesforceApiRequest.call(this, 'GET', '/sobjects/lead/describe'); for (const field of fields) { if (field.name === 'LeadSource') { for (const pickValue of field.picklistValues) { const pickValueName = pickValue.label; const pickValueId = pickValue.value; returnData.push({ name: pickValueName, value: pickValueId, }); } } } (0, GenericFunctions_1.sortOptions)(returnData); return returnData; }, // Get all the lead custom fields to display them to user so that they can // select them easily async getCustomFields() { const returnData = []; const resource = this.getNodeParameter('resource', 0); // TODO: find a way to filter this object to get just the lead sources instead of the whole object const { fields } = await GenericFunctions_1.salesforceApiRequest.call(this, 'GET', `/sobjects/${resource}/describe`); for (const field of fields) { if (field.custom === true) { const fieldName = field.label; const fieldId = field.name; returnData.push({ name: fieldName, value: fieldId, }); } } (0, GenericFunctions_1.sortOptions)(returnData); return returnData; }, // Get all the record types to display them to user so that they can // select them easily async getRecordTypes() { const returnData = []; let resource = this.getNodeParameter('resource', 0); if (resource === 'customObject') { resource = this.getNodeParameter('customObject', 0); } const qs = { q: `SELECT Id, Name, SobjectType, IsActive FROM RecordType WHERE SobjectType = '${resource}'`, }; const types = await GenericFunctions_1.salesforceApiRequestAllItems.call(this, 'records', 'GET', '/query', {}, qs); for (const type of types) { if (type.IsActive === true) { returnData.push({ name: type.Name, value: type.Id, }); } } (0, GenericFunctions_1.sortOptions)(returnData); return returnData; }, // Get all the external id fields to display them to user so that they can // select them easily async getExternalIdFields() { const returnData = []; let resource = this.getCurrentNodeParameter('resource'); resource = resource === 'customObject' ? this.getCurrentNodeParameter('customObject') : resource; const { fields } = await GenericFunctions_1.salesforceApiRequest.call(this, 'GET', `/sobjects/${resource}/describe`); for (const field of fields) { if (field.externalId === true || field.idLookup === true) { const fieldName = field.label; const fieldId = field.name; returnData.push({ name: fieldName, value: fieldId, }); } } (0, GenericFunctions_1.sortOptions)(returnData); return returnData; }, // Get all the accounts to display them to user so that they can // select them easily async getAccounts() { const returnData = []; const qs = { q: 'SELECT id, Name FROM Account', }; const accounts = await GenericFunctions_1.salesforceApiRequestAllItems.call(this, 'records', 'GET', '/query', {}, qs); for (const account of accounts) { const accountName = account.Name; const accountId = account.Id; returnData.push({ name: accountName, value: accountId, }); } (0, GenericFunctions_1.sortOptions)(returnData); return returnData; }, // Get all the campaigns to display them to user so that they can // select them easily async getCampaigns() { const returnData = []; const qs = { q: 'SELECT id, Name FROM Campaign', }; const campaigns = await GenericFunctions_1.salesforceApiRequestAllItems.call(this, 'records', 'GET', '/query', {}, qs); for (const campaign of campaigns) { const campaignName = campaign.Name; const campaignId = campaign.Id; returnData.push({ name: campaignName, value: campaignId, }); } (0, GenericFunctions_1.sortOptions)(returnData); return returnData; }, // Get all the stages to display them to user so that they can // select them easily async getStages() { const returnData = []; // TODO: find a way to filter this object to get just the lead sources instead of the whole object const { fields } = await GenericFunctions_1.salesforceApiRequest.call(this, 'GET', '/sobjects/opportunity/describe'); for (const field of fields) { if (field.name === 'StageName') { for (const pickValue of field.picklistValues) { const pickValueName = pickValue.label; const pickValueId = pickValue.value; returnData.push({ name: pickValueName, value: pickValueId, }); } } } (0, GenericFunctions_1.sortOptions)(returnData); return returnData; }, // Get all the stages to display them to user so that they can // select them easily async getAccountTypes() { const returnData = []; // TODO: find a way to filter this object to get just the lead sources instead of the whole object const { fields } = await GenericFunctions_1.salesforceApiRequest.call(this, 'GET', '/sobjects/account/describe'); for (const field of fields) { if (field.name === 'Type') { for (const pickValue of field.picklistValues) { const pickValueName = pickValue.label; const pickValueId = pickValue.value; returnData.push({ name: pickValueName, value: pickValueId, }); } } } (0, GenericFunctions_1.sortOptions)(returnData); return returnData; }, // Get all the account sources to display them to user so that they can // select them easily async getAccountSources() { const returnData = []; // TODO: find a way to filter this object to get just the lead sources instead of the whole object const { fields } = await GenericFunctions_1.salesforceApiRequest.call(this, 'GET', '/sobjects/account/describe'); for (const field of fields) { if (field.name === 'AccountSource') { for (const pickValue of field.picklistValues) { const pickValueName = pickValue.label; const pickValueId = pickValue.value; returnData.push({ name: pickValueName, value: pickValueId, }); } } } (0, GenericFunctions_1.sortOptions)(returnData); return returnData; }, // Get all the case types to display them to user so that they can // select them easily async getCaseTypes() { const returnData = []; // TODO: find a way to filter this object to get just the lead sources instead of the whole object const { fields } = await GenericFunctions_1.salesforceApiRequest.call(this, 'GET', '/sobjects/case/describe'); for (const field of fields) { if (field.name === 'Type') { for (const pickValue of field.picklistValues) { const pickValueName = pickValue.label; const pickValueId = pickValue.value; returnData.push({ name: pickValueName, value: pickValueId, }); } } } (0, GenericFunctions_1.sortOptions)(returnData); return returnData; }, // Get all the case statuses to display them to user so that they can // select them easily async getCaseStatuses() { const returnData = []; // TODO: find a way to filter this object to get just the lead sources instead of the whole object const { fields } = await GenericFunctions_1.salesforceApiRequest.call(this, 'GET', '/sobjects/case/describe'); for (const field of fields) { if (field.name === 'Status') { for (const pickValue of field.picklistValues) { const pickValueName = pickValue.label; const pickValueId = pickValue.value; returnData.push({ name: pickValueName, value: pickValueId, }); } } } (0, GenericFunctions_1.sortOptions)(returnData); return returnData; }, // Get all the case reasons to display them to user so that they can // select them easily async getCaseReasons() { const returnData = []; // TODO: find a way to filter this object to get just the lead sources instead of the whole object const { fields } = await GenericFunctions_1.salesforceApiRequest.call(this, 'GET', '/sobjects/case/describe'); for (const field of fields) { if (field.name === 'Reason') { for (const pickValue of field.picklistValues) { const pickValueName = pickValue.label; const pickValueId = pickValue.value; returnData.push({ name: pickValueName, value: pickValueId, }); } } } (0, GenericFunctions_1.sortOptions)(returnData); return returnData; }, // Get all the case origins to display them to user so that they can // select them easily async getCaseOrigins() { const returnData = []; // TODO: find a way to filter this object to get just the lead sources instead of the whole object const { fields } = await GenericFunctions_1.salesforceApiRequest.call(this, 'GET', '/sobjects/case/describe'); for (const field of fields) { if (field.name === 'Origin') { for (const pickValue of field.picklistValues) { const pickValueName = pickValue.label; const pickValueId = pickValue.value; returnData.push({ name: pickValueName, value: pickValueId, }); } } } (0, GenericFunctions_1.sortOptions)(returnData); return returnData; }, // Get all the case priorities to display them to user so that they can // select them easily async getCasePriorities() { const returnData = []; // TODO: find a way to filter this object to get just the lead sources instead of the whole object const { fields } = await GenericFunctions_1.salesforceApiRequest.call(this, 'GET', '/sobjects/case/describe'); for (const field of fields) { if (field.name === 'Priority') { for (const pickValue of field.picklistValues) { const pickValueName = pickValue.label; const pickValueId = pickValue.value; returnData.push({ name: pickValueName, value: pickValueId, }); } } } (0, GenericFunctions_1.sortOptions)(returnData); return returnData; }, // Get all the task statuses to display them to user so that they can // select them easily async getTaskStatuses() { const returnData = []; // TODO: find a way to filter this object to get just the lead sources instead of the whole object const { fields } = await GenericFunctions_1.salesforceApiRequest.call(this, 'GET', '/sobjects/task/describe'); for (const field of fields) { if (field.name === 'Status') { for (const pickValue of field.picklistValues) { const pickValueName = pickValue.label; const pickValueId = pickValue.value; returnData.push({ name: pickValueName, value: pickValueId, }); } } } (0, GenericFunctions_1.sortOptions)(returnData); return returnData; }, // Get all the task types to display them to user so that they can // select them easily async getTaskTypes() { const returnData = []; // TODO: find a way to filter this object to get just the lead sources instead of the whole object const { fields } = await GenericFunctions_1.salesforceApiRequest.call(this, 'GET', '/sobjects/task/describe'); for (const field of fields) { if (field.name === 'TaskSubtype') { for (const pickValue of field.picklistValues) { const pickValueName = pickValue.label; const pickValueId = pickValue.value; returnData.push({ name: pickValueName, value: pickValueId, }); } } } (0, GenericFunctions_1.sortOptions)(returnData); return returnData; }, // Get all the task subjects to display them to user so that they can // select them easily async getTaskSubjects() { const returnData = []; // TODO: find a way to filter this object to get just the lead sources instead of the whole object const { fields } = await GenericFunctions_1.salesforceApiRequest.call(this, 'GET', '/sobjects/task/describe'); for (const field of fields) { if (field.name === 'Subject') { for (const pickValue of field.picklistValues) { const pickValueName = pickValue.label; const pickValueId = pickValue.value; returnData.push({ name: pickValueName, value: pickValueId, }); } } } (0, GenericFunctions_1.sortOptions)(returnData); return returnData; }, // Get all the task call types to display them to user so that they can // select them easily async getTaskCallTypes() { const returnData = []; // TODO: find a way to filter this object to get just the lead sources instead of the whole object const { fields } = await GenericFunctions_1.salesforceApiRequest.call(this, 'GET', '/sobjects/task/describe'); for (const field of fields) { if (field.name === 'CallType') { for (const pickValue of field.picklistValues) { const pickValueName = pickValue.label; const pickValueId = pickValue.value; returnData.push({ name: pickValueName, value: pickValueId, }); } } } (0, GenericFunctions_1.sortOptions)(returnData); return returnData; }, // Get all the task call priorities to display them to user so that they can // select them easily async getTaskPriorities() { const returnData = []; // TODO: find a way to filter this object to get just the lead sources instead of the whole object const { fields } = await GenericFunctions_1.salesforceApiRequest.call(this, 'GET', '/sobjects/task/describe'); for (const field of fields) { if (field.name === 'Priority') { for (const pickValue of field.picklistValues) { const pickValueName = pickValue.label; const pickValueId = pickValue.value; returnData.push({ name: pickValueName, value: pickValueId, }); } } } (0, GenericFunctions_1.sortOptions)(returnData); return returnData; }, // Get all the task recurrence types to display them to user so that they can // select them easily async getTaskRecurrenceTypes() { const returnData = []; // TODO: find a way to filter this object to get just the lead sources instead of the whole object const { fields } = await GenericFunctions_1.salesforceApiRequest.call(this, 'GET', '/sobjects/task/describe'); for (const field of fields) { if (field.name === 'RecurrenceType') { for (const pickValue of field.picklistValues) { const pickValueName = pickValue.label; const pickValueId = pickValue.value; returnData.push({ name: pickValueName, value: pickValueId, }); } } } (0, GenericFunctions_1.sortOptions)(returnData); return returnData; }, // Get all the task recurrence instances to display them to user so that they can // select them easily async getTaskRecurrenceInstances() { const returnData = []; // TODO: find a way to filter this object to get just the lead sources instead of the whole object const { fields } = await GenericFunctions_1.salesforceApiRequest.call(this, 'GET', '/sobjects/task/describe'); for (const field of fields) { if (field.name === 'RecurrenceInstance') { for (const pickValue of field.picklistValues) { const pickValueName = pickValue.label; const pickValueId = pickValue.value; returnData.push({ name: pickValueName, value: pickValueId, }); } } } (0, GenericFunctions_1.sortOptions)(returnData); return returnData; }, // Get all the custom objects recurrence instances to display them to user so that they can // select them easily async getCustomObjects() { const returnData = []; // TODO: find a way to filter this object to get just the lead sources instead of the whole object const { sobjects: objects } = await GenericFunctions_1.salesforceApiRequest.call(this, 'GET', '/sobjects'); for (const object of objects) { if (object.custom === true) { const objectName = object.label; const objectId = object.name; returnData.push({ name: objectName, value: objectId, }); } } (0, GenericFunctions_1.sortOptions)(returnData); return returnData; }, // Get all the custom objects fields recurrence instances to display them to user so that they can // select them easily async getCustomObjectFields() { const returnData = []; // TODO: find a way to filter this object to get just the lead sources instead of the whole object const customObject = this.getCurrentNodeParameter('customObject'); const { fields } = await GenericFunctions_1.salesforceApiRequest.call(this, 'GET', `/sobjects/${customObject}/describe`); for (const field of fields) { const fieldName = field.label; const fieldId = field.name; returnData.push({ name: fieldName, value: fieldId, }); } (0, GenericFunctions_1.sortOptions)(returnData); return returnData; }, // Get all the account fields recurrence instances to display them to user so that they can // select them easily async getAccountFields() { const returnData = []; // TODO: find a way to filter this object to get just the lead sources instead of the whole object const { fields } = await GenericFunctions_1.salesforceApiRequest.call(this, 'GET', '/sobjects/account/describe'); for (const field of fields) { const fieldName = field.label; const fieldId = field.name; returnData.push({ name: fieldName, value: fieldId, }); } (0, GenericFunctions_1.sortOptions)(returnData); return returnData; }, // Get all the attachment fields recurrence instances to display them to user so that they can // select them easily async getAtachmentFields() { const returnData = []; // TODO: find a way to filter this object to get just the lead sources instead of the whole object const { fields } = await GenericFunctions_1.salesforceApiRequest.call(this, 'GET', '/sobjects/attachment/describe'); for (const field of fields) { const fieldName = field.label; const fieldId = field.name; returnData.push({ name: fieldName, value: fieldId, }); } (0, GenericFunctions_1.sortOptions)(returnData); return returnData; }, // Get all the case fields recurrence instances to display them to user so that they can // select them easily async getCaseFields() { const returnData = []; // TODO: find a way to filter this object to get just the lead sources instead of the whole object const { fields } = await GenericFunctions_1.salesforceApiRequest.call(this, 'GET', '/sobjects/case/describe'); for (const field of fields) { const fieldName = field.label; const fieldId = field.name; returnData.push({ name: fieldName, value: fieldId, }); } (0, GenericFunctions_1.sortOptions)(returnData); return returnData; }, // Get all the lead fields recurrence instances to display them to user so that they can // select them easily async getLeadFields() { const returnData = []; // TODO: find a way to filter this object to get just the lead sources instead of the whole object const { fields } = await GenericFunctions_1.salesforceApiRequest.call(this, 'GET', '/sobjects/lead/describe'); for (const field of fields) { const fieldName = field.label; const fieldId = field.name; returnData.push({ name: fieldName, value: fieldId, }); } (0, GenericFunctions_1.sortOptions)(returnData); return returnData; }, // Get all the opportunity fields recurrence instances to display them to user so that they can // select them easily async getOpportunityFields() { const returnData = []; // TODO: find a way to filter this object to get just the lead sources instead of the whole object const { fields } = await GenericFunctions_1.salesforceApiRequest.call(this, 'GET', '/sobjects/opportunity/describe'); for (const field of fields) { const fieldName = field.label; const fieldId = field.name; returnData.push({ name: fieldName, value: fieldId, }); } (0, GenericFunctions_1.sortOptions)(returnData); return returnData; }, // Get all the opportunity fields recurrence instances to display them to user so that they can // select them easily async getTaskFields() { const returnData = []; // TODO: find a way to filter this object to get just the lead sources instead of the whole object const { fields } = await GenericFunctions_1.salesforceApiRequest.call(this, 'GET', '/sobjects/task/describe'); for (const field of fields) { const fieldName = field.label; const fieldId = field.name; returnData.push({ name: fieldName, value: fieldId, }); } (0, GenericFunctions_1.sortOptions)(returnData); return returnData; }, // Get all the users fields recurrence instances to display them to user so that they can // select them easily async getUserFields() { const returnData = []; // TODO: find a way to filter this object to get just the lead sources instead of the whole object const { fields } = await GenericFunctions_1.salesforceApiRequest.call(this, 'GET', '/sobjects/user/describe'); for (const field of fields) { const fieldName = field.label; const fieldId = field.name; returnData.push({ name: fieldName, value: fieldId, }); } (0, GenericFunctions_1.sortOptions)(returnData); return returnData; }, // Get all the contact fields recurrence instances to display them to user so that they can // select them easily async getContactFields() { const returnData = []; // TODO: find a way to filter this object to get just the lead sources instead of the whole object const { fields } = await GenericFunctions_1.salesforceApiRequest.call(this, 'GET', '/sobjects/contact/describe'); for (const field of fields) { const fieldName = field.label; const fieldId = field.name; returnData.push({ name: fieldName, value: fieldId, }); } (0, GenericFunctions_1.sortOptions)(returnData); return returnData; }, // // Get all folders to display them to user so that they can // // select them easily // async getFolders(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> { // const returnData: INodePropertyOptions[] = []; // const fields = await salesforceApiRequestAllItems.call(this, 'records', 'GET', '/sobjects/folder/describe'); // this.logger.debug(JSON.stringify(fields, undefined, 2)) // const qs = { // //ContentFolderItem ContentWorkspace ContentFolder // q: `SELECT Id, Title FROM ContentVersion`, // //q: `SELECT Id FROM Folder where Type = 'Document'`, // }; // const folders = await salesforceApiRequestAllItems.call(this, 'records', 'GET', '/query', {}, qs); // for (const folder of folders) { // returnData.push({ // name: folder.Name, // value: folder.Id, // }); // } // return returnData; // }, }, }; async execute() { const items = this.getInputData(); const returnData = []; let responseData; const qs = {}; const resource = this.getNodeParameter('resource', 0); const operation = this.getNodeParameter('operation', 0); this.logger.debug(`Running "Salesforce" node named "${this.getNode.name}" resource "${resource}" operation "${operation}"`); for (let i = 0; i < items.length; i++) { try { if (resource === 'lead') { //https://developer.salesforce.com/docs/api-explorer/sobject/Lead/post-lead if (operation === 'create' || operation === 'upsert') { const company = this.getNodeParameter('company', i); const lastname = this.getNodeParameter('lastname', i); const additionalFields = this.getNodeParameter('additionalFields', i); const body = { Company: company, LastName: lastname, }; if (additionalFields.hasOptedOutOfEmail !== undefined) { body.HasOptedOutOfEmail = additionalFields.hasOptedOutOfEmail; } if (additionalFields.hasOptedOutOfFax !== undefined) { body.HasOptedOutOfFax = additionalFields.hasOptedOutOfFax; } if (additionalFields.email !== undefined) { body.Email = additionalFields.email; } if (additionalFields.city !== undefined) { body.City = additionalFields.city; } if (additionalFields.phone !== undefined) { body.Phone = additionalFields.phone; } if (additionalFields.state !== undefined) { body.State = additionalFields.state; } if (additionalFields.title !== undefined) { body.Title = additionalFields.title; } if (additionalFields.jigsaw !== undefined) { body.Jigsaw = additionalFields.jigsaw; } if (additionalFields.rating !== undefined) { body.Rating = additionalFields.rating; } if (additionalFields.status !== undefined) { body.Status = additionalFields.status; } if (additionalFields.street !== undefined) { body.Street = additionalFields.street; } if (additionalFields.country !== undefined) { body.Country = additionalFields.country; } if (additionalFields.owner !== undefined) { body.OwnerId = additionalFields.owner; } if (additionalFields.website !== undefined) { body.Website = additionalFields.website; } if (additionalFields.industry !== undefined) { body.Industry = additionalFields.industry; } if (additionalFields.fax !== undefined) { body.Fax = additionalFields.fax; } if (additionalFields.firstname !== undefined) { body.FirstName = additionalFields.firstname; } if (additionalFields.leadSource !== undefined) { body.LeadSource = additionalFields.leadSource; } if (additionalFields.postalCode !== undefined) { body.PostalCode = additionalFields.postalCode; } if (additionalFields.salutation !== undefined) { body.Salutation = additionalFields.salutation; } if (additionalFields.description !== undefined) { body.Description = additionalFields.description; } if (additionalFields.annualRevenue !== undefined) { body.AnnualRevenue = additionalFields.annualRevenue; } if (additionalFields.isUnreadByOwner !== undefined) { body.IsUnreadByOwner = additionalFields.isUnreadByOwner; } if (additionalFields.numberOfEmployees !== undefined) { body.NumberOfEmployees = additionalFields.numberOfEmployees; } if (additionalFields.mobilePhone !== undefined) { body.MobilePhone = additionalFields.mobilePhone; } if (additionalFields.recordTypeId !== undefined) { body.RecordTypeId = additionalFiel