diff --git a/packages/nodes-base/nodes/Salesforce/AccountDescription.ts b/packages/nodes-base/nodes/Salesforce/AccountDescription.ts index 6b03793360..b00a4331dc 100644 --- a/packages/nodes-base/nodes/Salesforce/AccountDescription.ts +++ b/packages/nodes-base/nodes/Salesforce/AccountDescription.ts @@ -291,6 +291,15 @@ export const accountFields = [ default: '', description: 'Phone number for the account.', }, + { + displayName: 'Record Type ID', + name: 'recordTypeId', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getRecordTypes', + }, + default: '', + }, { displayName: 'SicDesc', name: 'sicDesc', @@ -539,6 +548,15 @@ export const accountFields = [ default: '', description: 'Phone number for the account.', }, + { + displayName: 'Record Type ID', + name: 'recordTypeId', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getRecordTypes', + }, + default: '', + }, { displayName: 'Type', name: 'type', diff --git a/packages/nodes-base/nodes/Salesforce/CaseDescription.ts b/packages/nodes-base/nodes/Salesforce/CaseDescription.ts index 69bed22293..aadf26e206 100644 --- a/packages/nodes-base/nodes/Salesforce/CaseDescription.ts +++ b/packages/nodes-base/nodes/Salesforce/CaseDescription.ts @@ -208,6 +208,15 @@ export const caseFields = [ default: '', description: 'The reason why the case was created, such as Instructions not clear, or User didn’t attend training.', }, + { + displayName: 'Record Type ID', + name: 'recordTypeId', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getRecordTypes', + }, + default: '', + }, { displayName: 'Status', name: 'status', @@ -405,6 +414,15 @@ export const caseFields = [ default: '', description: 'The reason why the case was created, such as Instructions not clear, or User didn’t attend training.', }, + { + displayName: 'Record Type ID', + name: 'recordTypeId', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getRecordTypes', + }, + default: '', + }, { displayName: 'Status', name: 'status', diff --git a/packages/nodes-base/nodes/Salesforce/CaseInterface.ts b/packages/nodes-base/nodes/Salesforce/CaseInterface.ts index 169d47c14d..76ac5016c9 100644 --- a/packages/nodes-base/nodes/Salesforce/CaseInterface.ts +++ b/packages/nodes-base/nodes/Salesforce/CaseInterface.ts @@ -16,6 +16,7 @@ export interface ICase { SuppliedEmail?: string; SuppliedPhone?: string; SuppliedCompany?: string; + RecordTypeId?: string; } export interface ICaseComment { diff --git a/packages/nodes-base/nodes/Salesforce/ContactDescription.ts b/packages/nodes-base/nodes/Salesforce/ContactDescription.ts index 4e9901fc6e..e47db24b0d 100644 --- a/packages/nodes-base/nodes/Salesforce/ContactDescription.ts +++ b/packages/nodes-base/nodes/Salesforce/ContactDescription.ts @@ -384,6 +384,15 @@ export const contactFields = [ default: '', description: 'Phone number for the contact.', }, + { + displayName: 'Record Type ID', + name: 'recordTypeId', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getRecordTypes', + }, + default: '', + }, { displayName: 'Salutation', name: 'salutation', @@ -680,6 +689,15 @@ export const contactFields = [ default: '', description: 'Phone number for the contact.', }, + { + displayName: 'Record Type ID', + name: 'recordTypeId', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getRecordTypes', + }, + default: '', + }, { displayName: 'Salutation', name: 'salutation', diff --git a/packages/nodes-base/nodes/Salesforce/CustomObjectDescription.ts b/packages/nodes-base/nodes/Salesforce/CustomObjectDescription.ts index 35f6c7f32e..972633ed79 100644 --- a/packages/nodes-base/nodes/Salesforce/CustomObjectDescription.ts +++ b/packages/nodes-base/nodes/Salesforce/CustomObjectDescription.ts @@ -512,4 +512,67 @@ export const customObjectFields = [ }, ], }, + { + displayName: 'Additional Fields', + name: 'additionalFields', + type: 'collection', + displayOptions: { + show: { + operation: [ + 'create', + 'upsert', + ], + resource: [ + 'customObject', + ], + }, + }, + default: {}, + placeholder: 'Add Field', + options: [ + { + displayName: 'Record Type ID', + name: 'recordTypeId', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getRecordTypes', + loadOptionsDependsOn: [ + 'customObject', + ], + }, + default: '', + }, + ], + }, + { + displayName: 'Update Fields', + name: 'updateFields', + type: 'collection', + displayOptions: { + show: { + operation: [ + 'update', + ], + resource: [ + 'customObject', + ], + }, + }, + default: {}, + placeholder: 'Add Field', + options: [ + { + displayName: 'Record Type ID', + name: 'recordTypeId', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getRecordTypes', + loadOptionsDependsOn: [ + 'customObject', + ], + }, + default: '', + }, + ], + }, ] as INodeProperties[]; diff --git a/packages/nodes-base/nodes/Salesforce/LeadDescription.ts b/packages/nodes-base/nodes/Salesforce/LeadDescription.ts index cff54682c1..fe33c3eb45 100644 --- a/packages/nodes-base/nodes/Salesforce/LeadDescription.ts +++ b/packages/nodes-base/nodes/Salesforce/LeadDescription.ts @@ -320,6 +320,15 @@ export const leadFields = [ default: '', description: 'Postal code for the address of the lead. Label is Zip/Postal Code.', }, + { + displayName: 'Record Type ID', + name: 'recordTypeId', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getRecordTypes', + }, + default: '', + }, { displayName: 'Rating', name: 'rating', @@ -578,6 +587,15 @@ export const leadFields = [ default: '', description: 'Phone number for the lead.', }, + { + displayName: 'Record Type ID', + name: 'recordTypeId', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getRecordTypes', + }, + default: '', + }, { displayName: 'Rating', name: 'rating', diff --git a/packages/nodes-base/nodes/Salesforce/Salesforce.node.ts b/packages/nodes-base/nodes/Salesforce/Salesforce.node.ts index b91ad6cb16..b8a61e32f6 100644 --- a/packages/nodes-base/nodes/Salesforce/Salesforce.node.ts +++ b/packages/nodes-base/nodes/Salesforce/Salesforce.node.ts @@ -121,6 +121,7 @@ import { import { LoggerProxy as Logger, } from 'n8n-workflow'; +import { query } from '../Elasticsearch/descriptions/placeholders'; export class Salesforce implements INodeType { description: INodeTypeDescription = { @@ -408,7 +409,6 @@ export class Salesforce implements INodeType { const resource = this.getNodeParameter('resource', 0) as string; // TODO: find a way to filter this object to get just the lead sources instead of the whole object const { fields } = await salesforceApiRequest.call(this, 'GET', `/sobjects/${resource}/describe`); - for (const field of fields) { if (field.custom === true) { const fieldName = field.label; @@ -422,6 +422,29 @@ export class Salesforce implements INodeType { sortOptions(returnData); return returnData; }, + // Get all the record types to display them to user so that he can + // select them easily + async getRecordTypes(this: ILoadOptionsFunctions): Promise { + const returnData: INodePropertyOptions[] = []; + let resource = this.getNodeParameter('resource', 0) as string; + if (resource === 'customObject') { + resource = this.getNodeParameter('customObject', 0) as string; + } + const qs = { + q: `SELECT Id, Name, SobjectType, IsActive FROM RecordType WHERE SobjectType = '${resource}'`, + }; + const types = await salesforceApiRequestAllItems.call(this, 'records', 'GET', '/query', {}, qs); + for (const type of types) { + if (type.IsActive === true) { + returnData.push({ + name: type.Name, + value: type.Id, + }); + } + } + sortOptions(returnData); + return returnData; + }, // Get all the external id fields to display them to user so that he can // select them easily async getExternalIdFields(this: ILoadOptionsFunctions): Promise { @@ -1061,6 +1084,9 @@ export class Salesforce implements INodeType { if (additionalFields.mobilePhone !== undefined) { body.MobilePhone = additionalFields.mobilePhone as string; } + if (additionalFields.recordTypeId !== undefined) { + body.RecordTypeId = additionalFields.recordTypeId as string; + } if (additionalFields.customFieldsUi) { const customFields = (additionalFields.customFieldsUi as IDataObject).customFieldsValues as IDataObject[]; if (customFields) { @@ -1163,6 +1189,9 @@ export class Salesforce implements INodeType { if (updateFields.mobilePhone !== undefined) { body.MobilePhone = updateFields.mobilePhone as string; } + if (updateFields.recordTypeId !== undefined) { + body.RecordTypeId = updateFields.recordTypeId as string; + } if (updateFields.customFieldsUi) { const customFields = (updateFields.customFieldsUi as IDataObject).customFieldsValues as IDataObject[]; if (customFields) { @@ -1267,6 +1296,9 @@ export class Salesforce implements INodeType { if (additionalFields.jigsaw !== undefined) { body.Jigsaw = additionalFields.jigsaw as string; } + if (additionalFields.recordTypeId !== undefined) { + body.RecordTypeId = additionalFields.recordTypeId as string; + } if (additionalFields.owner !== undefined) { body.OwnerId = additionalFields.owner as string; } @@ -1381,6 +1413,9 @@ export class Salesforce implements INodeType { if (updateFields.email !== undefined) { body.Email = updateFields.email as string; } + if (updateFields.recordTypeId !== undefined) { + body.RecordTypeId = updateFields.recordTypeId as string; + } if (updateFields.phone !== undefined) { body.Phone = updateFields.phone as string; } @@ -1551,6 +1586,7 @@ export class Salesforce implements INodeType { if (operation === 'create' || operation === 'upsert') { const customObject = this.getNodeParameter('customObject', i) as string; const customFieldsUi = this.getNodeParameter('customFieldsUi', i) as IDataObject; + const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; const body: IDataObject = {}; if (customFieldsUi) { const customFields = (customFieldsUi as IDataObject).customFieldsValues as IDataObject[]; @@ -1561,6 +1597,9 @@ export class Salesforce implements INodeType { } } } + if (additionalFields.recordTypeId) { + body.RecordTypeId = additionalFields.recordTypeId as string; + } let endpoint = `/sobjects/${customObject}`; let method = 'POST'; if (operation === 'upsert') { @@ -1578,7 +1617,11 @@ export class Salesforce implements INodeType { const recordId = this.getNodeParameter('recordId', i) as string; const customObject = this.getNodeParameter('customObject', i) as string; const customFieldsUi = this.getNodeParameter('customFieldsUi', i) as IDataObject; + const updateFields = this.getNodeParameter('updateFields', i) as IDataObject; const body: IDataObject = {}; + if (updateFields.recordTypeId) { + body.RecordTypeId = updateFields.recordTypeId as string; + } if (customFieldsUi) { const customFields = (customFieldsUi as IDataObject).customFieldsValues as IDataObject[]; if (customFields) { @@ -1926,6 +1969,9 @@ export class Salesforce implements INodeType { if (additionalFields.shippingPostalCode !== undefined) { body.ShippingPostalCode = additionalFields.shippingPostalCode as string; } + if (additionalFields.recordTypeId !== undefined) { + body.RecordTypeId = additionalFields.recordTypeId as string; + } if (additionalFields.customFieldsUi) { const customFields = (additionalFields.customFieldsUi as IDataObject).customFieldsValues as IDataObject[]; if (customFields) { @@ -1974,6 +2020,9 @@ export class Salesforce implements INodeType { if (updateFields.sicDesc !== undefined) { body.SicDesc = updateFields.sicDesc as string; } + if (updateFields.recordTypeId !== undefined) { + body.RecordTypeId = updateFields.recordTypeId as string; + } if (updateFields.website !== undefined) { body.Website = updateFields.website as string; } @@ -2145,6 +2194,9 @@ export class Salesforce implements INodeType { if (additionalFields.suppliedCompany !== undefined) { body.SuppliedCompany = additionalFields.suppliedCompany as string; } + if (additionalFields.recordTypeId !== undefined) { + body.RecordTypeId = additionalFields.recordTypeId as string; + } if (additionalFields.customFieldsUi) { const customFields = (additionalFields.customFieldsUi as IDataObject).customFieldsValues as IDataObject[]; if (customFields) { @@ -2185,6 +2237,9 @@ export class Salesforce implements INodeType { if (updateFields.accountId !== undefined) { body.AccountId = updateFields.accountId as string; } + if (updateFields.recordTypeId !== undefined) { + body.RecordTypeId = updateFields.recordTypeId as string; + } if (updateFields.contactId !== undefined) { body.ContactId = updateFields.contactId as string; }