2020-02-10 12:55:28 -08:00
import {
IExecuteFunctions ,
} from 'n8n-core' ;
2020-02-12 22:35:56 -08:00
2020-02-10 12:55:28 -08:00
import {
IDataObject ,
ILoadOptionsFunctions ,
INodeExecutionData ,
INodeType ,
2020-02-12 22:35:56 -08:00
INodeTypeDescription ,
2020-02-10 12:55:28 -08:00
INodePropertyOptions ,
} from 'n8n-workflow' ;
2020-02-12 22:35:56 -08:00
2020-02-10 12:55:28 -08:00
import {
2020-02-12 22:35:56 -08:00
accountFields ,
accountOperations ,
} from './AccountDescription' ;
2020-02-10 12:55:28 -08:00
import {
2020-02-12 22:35:56 -08:00
IAccount ,
} from './AccountInterface' ;
import {
attachmentFields ,
attachmentOperations ,
} from './AttachmentDescription' ;
import {
IAttachment ,
} from './AttachmentInterface' ;
import {
ICampaignMember ,
} from './CampaignMemberInterface' ;
import {
caseFields ,
caseOperations ,
} from './CaseDescription' ;
import {
ICase ,
ICaseComment ,
} from './CaseInterface' ;
2020-02-10 12:55:28 -08:00
import {
contactFields ,
contactOperations ,
} from './ContactDescription' ;
import {
2020-02-12 22:35:56 -08:00
IContact ,
} from './ContactInterface' ;
2020-02-10 12:55:28 -08:00
import {
2020-02-12 22:35:56 -08:00
salesforceApiRequest ,
salesforceApiRequestAllItems ,
} from './GenericFunctions' ;
import {
leadFields ,
leadOperations ,
} from './LeadDescription' ;
2020-02-10 12:55:28 -08:00
import {
ILead ,
} from './LeadInterface' ;
import {
INote ,
} from './NoteInterface' ;
import {
2020-02-12 22:35:56 -08:00
opportunityFields ,
opportunityOperations ,
} from './OpportunityDescription' ;
import {
IOpportunity ,
} from './OpportunityInterface' ;
import {
taskFields ,
taskOperations ,
} from './TaskDescription' ;
2020-02-10 12:55:28 -08:00
import {
ITask ,
} from './TaskInterface' ;
2020-02-12 22:35:56 -08:00
2020-02-10 12:55:28 -08:00
export class Salesforce implements INodeType {
description : INodeTypeDescription = {
displayName : 'Salesforce' ,
name : 'salesforce' ,
icon : 'file:salesforce.png' ,
group : [ 'output' ] ,
version : 1 ,
subtitle : '={{$parameter["operation"] + ": " + $parameter["resource"]}}' ,
description : 'Consume Salesforce API' ,
defaults : {
name : 'Salesforce' ,
color : '#429fd9' ,
} ,
inputs : [ 'main' ] ,
outputs : [ 'main' ] ,
credentials : [
{
name : 'salesforceOAuth2Api' ,
required : true ,
} ,
] ,
properties : [
{
displayName : 'Resource' ,
name : 'resource' ,
type : 'options' ,
options : [
{
2020-02-12 22:35:56 -08:00
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.' ,
2020-02-10 12:55:28 -08:00
} ,
{
name : 'Contact' ,
value : 'contact' ,
description : 'Represents a contact, which is an individual associated with an account.' ,
} ,
2020-02-12 22:35:56 -08:00
{
name : 'Lead' ,
value : 'lead' ,
description : 'Represents a prospect or potential .' ,
} ,
2020-02-10 12:55:28 -08:00
{
name : 'Opportunity' ,
value : 'opportunity' ,
description : 'Represents an opportunity, which is a sale or pending deal.' ,
} ,
{
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.' ,
} ,
2020-02-12 22:35:56 -08:00
2020-02-10 12:55:28 -08:00
] ,
default : 'lead' ,
description : 'Resource to consume.' ,
} ,
. . . leadOperations ,
. . . leadFields ,
. . . contactOperations ,
. . . contactFields ,
. . . opportunityOperations ,
. . . opportunityFields ,
. . . accountOperations ,
. . . accountFields ,
. . . caseOperations ,
. . . caseFields ,
. . . taskOperations ,
. . . taskFields ,
. . . attachmentOperations ,
. . . attachmentFields ,
] ,
} ;
methods = {
loadOptions : {
// Get all the lead statuses to display them to user so that he can
// select them easily
async getLeadStatuses ( this : ILoadOptionsFunctions ) : Promise < INodePropertyOptions [ ] > {
const returnData : INodePropertyOptions [ ] = [ ] ;
const qs = {
q : 'SELECT id, MasterLabel FROM LeadStatus' ,
} ;
const statuses = await salesforceApiRequestAllItems . call ( this , 'records' , 'GET' , '/query' , { } , qs ) ;
for ( const status of statuses ) {
const statusName = status . MasterLabel ;
const statusId = status . Id ;
returnData . push ( {
name : statusName ,
value : statusId ,
} ) ;
}
return returnData ;
} ,
// Get all the users to display them to user so that he can
// select them easily
async getUsers ( this : ILoadOptionsFunctions ) : Promise < INodePropertyOptions [ ] > {
const returnData : INodePropertyOptions [ ] = [ ] ;
const qs = {
q : 'SELECT id, Name FROM User' ,
} ;
const users = await 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 ,
} ) ;
}
return returnData ;
} ,
// Get all the lead sources to display them to user so that he can
// select them easily
async getLeadSources ( this : ILoadOptionsFunctions ) : Promise < INodePropertyOptions [ ] > {
const returnData : INodePropertyOptions [ ] = [ ] ;
2020-02-12 22:35:56 -08:00
// TODO: find a way to filter this object to get just the lead sources instead of the whole object
2020-02-10 12:55:28 -08:00
const { fields } = await 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 ,
} ) ;
}
}
}
return returnData ;
} ,
// Get all the accounts to display them to user so that he can
// select them easily
async getAccounts ( this : ILoadOptionsFunctions ) : Promise < INodePropertyOptions [ ] > {
const returnData : INodePropertyOptions [ ] = [ ] ;
const qs = {
q : 'SELECT id, Name FROM Account' ,
} ;
const accounts = await 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 ,
} ) ;
}
return returnData ;
} ,
// Get all the campaigns to display them to user so that he can
// select them easily
async getCampaigns ( this : ILoadOptionsFunctions ) : Promise < INodePropertyOptions [ ] > {
const returnData : INodePropertyOptions [ ] = [ ] ;
const qs = {
q : 'SELECT id, Name FROM Campaign' ,
} ;
const campaigns = await 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 ,
} ) ;
}
return returnData ;
} ,
// Get all the stages to display them to user so that he can
// select them easily
async getStages ( this : ILoadOptionsFunctions ) : Promise < INodePropertyOptions [ ] > {
const returnData : INodePropertyOptions [ ] = [ ] ;
2020-02-12 22:35:56 -08:00
// TODO: find a way to filter this object to get just the lead sources instead of the whole object
2020-02-10 12:55:28 -08:00
const { fields } = await 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 ,
} ) ;
}
}
}
return returnData ;
} ,
// Get all the stages to display them to user so that he can
// select them easily
async getAccountTypes ( this : ILoadOptionsFunctions ) : Promise < INodePropertyOptions [ ] > {
const returnData : INodePropertyOptions [ ] = [ ] ;
2020-02-12 22:35:56 -08:00
// TODO: find a way to filter this object to get just the lead sources instead of the whole object
2020-02-10 12:55:28 -08:00
const { fields } = await 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 ,
} ) ;
}
}
}
return returnData ;
} ,
// Get all the account sources to display them to user so that he can
// select them easily
async getAccountSources ( this : ILoadOptionsFunctions ) : Promise < INodePropertyOptions [ ] > {
const returnData : INodePropertyOptions [ ] = [ ] ;
2020-02-12 22:35:56 -08:00
// TODO: find a way to filter this object to get just the lead sources instead of the whole object
2020-02-10 12:55:28 -08:00
const { fields } = await 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 ,
} ) ;
}
}
}
return returnData ;
} ,
// Get all the case types to display them to user so that he can
// select them easily
async getCaseTypes ( this : ILoadOptionsFunctions ) : Promise < INodePropertyOptions [ ] > {
const returnData : INodePropertyOptions [ ] = [ ] ;
2020-02-12 22:35:56 -08:00
// TODO: find a way to filter this object to get just the lead sources instead of the whole object
2020-02-10 12:55:28 -08:00
const { fields } = await 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 ,
} ) ;
}
}
}
return returnData ;
} ,
// Get all the case statuses to display them to user so that he can
// select them easily
async getCaseStatuses ( this : ILoadOptionsFunctions ) : Promise < INodePropertyOptions [ ] > {
const returnData : INodePropertyOptions [ ] = [ ] ;
2020-02-12 22:35:56 -08:00
// TODO: find a way to filter this object to get just the lead sources instead of the whole object
2020-02-10 12:55:28 -08:00
const { fields } = await 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 ,
} ) ;
}
}
}
return returnData ;
} ,
// Get all the case reasons to display them to user so that he can
// select them easily
async getCaseReasons ( this : ILoadOptionsFunctions ) : Promise < INodePropertyOptions [ ] > {
const returnData : INodePropertyOptions [ ] = [ ] ;
2020-02-12 22:35:56 -08:00
// TODO: find a way to filter this object to get just the lead sources instead of the whole object
2020-02-10 12:55:28 -08:00
const { fields } = await 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 ,
} ) ;
}
}
}
return returnData ;
} ,
// Get all the case origins to display them to user so that he can
// select them easily
async getCaseOrigins ( this : ILoadOptionsFunctions ) : Promise < INodePropertyOptions [ ] > {
const returnData : INodePropertyOptions [ ] = [ ] ;
2020-02-12 22:35:56 -08:00
// TODO: find a way to filter this object to get just the lead sources instead of the whole object
2020-02-10 12:55:28 -08:00
const { fields } = await 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 ,
} ) ;
}
}
}
return returnData ;
} ,
// Get all the case priorities to display them to user so that he can
// select them easily
async getCasePriorities ( this : ILoadOptionsFunctions ) : Promise < INodePropertyOptions [ ] > {
const returnData : INodePropertyOptions [ ] = [ ] ;
2020-02-12 22:35:56 -08:00
// TODO: find a way to filter this object to get just the lead sources instead of the whole object
2020-02-10 12:55:28 -08:00
const { fields } = await 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 ,
} ) ;
}
}
}
return returnData ;
} ,
// Get all the task statuses to display them to user so that he can
// select them easily
async getTaskStatuses ( this : ILoadOptionsFunctions ) : Promise < INodePropertyOptions [ ] > {
const returnData : INodePropertyOptions [ ] = [ ] ;
2020-02-12 22:35:56 -08:00
// TODO: find a way to filter this object to get just the lead sources instead of the whole object
2020-02-10 12:55:28 -08:00
const { fields } = await 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 ,
} ) ;
}
}
}
return returnData ;
} ,
// Get all the task subjects to display them to user so that he can
// select them easily
async getTaskSubjects ( this : ILoadOptionsFunctions ) : Promise < INodePropertyOptions [ ] > {
const returnData : INodePropertyOptions [ ] = [ ] ;
2020-02-12 22:35:56 -08:00
// TODO: find a way to filter this object to get just the lead sources instead of the whole object
2020-02-10 12:55:28 -08:00
const { fields } = await 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 ,
} ) ;
}
}
}
return returnData ;
} ,
// Get all the task call types to display them to user so that he can
// select them easily
async getTaskCallTypes ( this : ILoadOptionsFunctions ) : Promise < INodePropertyOptions [ ] > {
const returnData : INodePropertyOptions [ ] = [ ] ;
2020-02-12 22:35:56 -08:00
// TODO: find a way to filter this object to get just the lead sources instead of the whole object
2020-02-10 12:55:28 -08:00
const { fields } = await 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 ,
} ) ;
}
}
}
return returnData ;
} ,
// Get all the task call priorities to display them to user so that he can
// select them easily
async getTaskPriorities ( this : ILoadOptionsFunctions ) : Promise < INodePropertyOptions [ ] > {
const returnData : INodePropertyOptions [ ] = [ ] ;
2020-02-12 22:35:56 -08:00
// TODO: find a way to filter this object to get just the lead sources instead of the whole object
2020-02-10 12:55:28 -08:00
const { fields } = await 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 ,
} ) ;
}
}
}
return returnData ;
} ,
// Get all the task recurrence types to display them to user so that he can
// select them easily
async getTaskRecurrenceTypes ( this : ILoadOptionsFunctions ) : Promise < INodePropertyOptions [ ] > {
const returnData : INodePropertyOptions [ ] = [ ] ;
2020-02-12 22:35:56 -08:00
// TODO: find a way to filter this object to get just the lead sources instead of the whole object
2020-02-10 12:55:28 -08:00
const { fields } = await 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 ,
} ) ;
}
}
}
return returnData ;
} ,
// Get all the task recurrence instances to display them to user so that he can
// select them easily
async getTaskRecurrenceInstances ( this : ILoadOptionsFunctions ) : Promise < INodePropertyOptions [ ] > {
const returnData : INodePropertyOptions [ ] = [ ] ;
2020-02-12 22:35:56 -08:00
// TODO: find a way to filter this object to get just the lead sources instead of the whole object
2020-02-10 12:55:28 -08:00
const { fields } = await 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 ,
} ) ;
}
}
}
return returnData ;
} ,
} ,
} ;
async execute ( this : IExecuteFunctions ) : Promise < INodeExecutionData [ ] [ ] > {
const items = this . getInputData ( ) ;
const returnData : IDataObject [ ] = [ ] ;
let responseData ;
const qs : IDataObject = { } ;
const resource = this . getNodeParameter ( 'resource' , 0 ) as string ;
const operation = this . getNodeParameter ( 'operation' , 0 ) as string ;
2020-02-12 22:35:56 -08:00
for ( let i = 0 ; i < items . length ; i ++ ) {
2020-02-10 12:55:28 -08:00
if ( resource === 'lead' ) {
//https://developer.salesforce.com/docs/api-explorer/sobject/Lead/post-lead
if ( operation === 'create' ) {
const company = this . getNodeParameter ( 'company' , i ) as string ;
const lastname = this . getNodeParameter ( 'lastname' , i ) as string ;
const additionalFields = this . getNodeParameter ( 'additionalFields' , i ) as IDataObject ;
const body : ILead = {
Company : company ,
LastName : lastname ,
} ;
2020-08-26 23:16:50 -07:00
if ( additionalFields . email !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Email = additionalFields . email as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . city !== undefined ) {
2020-02-10 12:55:28 -08:00
body . City = additionalFields . city as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . phone !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Phone = additionalFields . phone as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . state !== undefined ) {
2020-02-10 12:55:28 -08:00
body . State = additionalFields . state as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . title !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Title = additionalFields . title as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . jigsaw !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Jigsaw = additionalFields . jigsaw as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . rating !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Rating = additionalFields . rating as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . status !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Status = additionalFields . status as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . street !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Street = additionalFields . street as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . country !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Country = additionalFields . country as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . owner !== undefined ) {
2020-02-10 12:55:28 -08:00
body . OwnerId = additionalFields . owner as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . website !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Website = additionalFields . website as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . industry !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Industry = additionalFields . industry as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . firstName !== undefined ) {
2020-02-10 12:55:28 -08:00
body . FirstName = additionalFields . firstName as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . leadSource !== undefined ) {
2020-02-10 12:55:28 -08:00
body . LeadSource = additionalFields . leadSource as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . postalCode !== undefined ) {
2020-02-10 12:55:28 -08:00
body . PostalCode = additionalFields . postalCode as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . salutation !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Salutation = additionalFields . salutation as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . description !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Description = additionalFields . description as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . annualRevenue !== undefined ) {
2020-02-10 12:55:28 -08:00
body . AnnualRevenue = additionalFields . annualRevenue as number ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . isUnreadByOwner !== undefined ) {
2020-02-10 12:55:28 -08:00
body . IsUnreadByOwner = additionalFields . isUnreadByOwner as boolean ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . numberOfEmployees !== undefined ) {
2020-02-10 12:55:28 -08:00
body . NumberOfEmployees = additionalFields . numberOfEmployees as number ;
}
responseData = await salesforceApiRequest . call ( this , 'POST' , '/sobjects/lead' , body ) ;
}
//https://developer.salesforce.com/docs/api-explorer/sobject/Lead/patch-lead-id
if ( operation === 'update' ) {
const leadId = this . getNodeParameter ( 'leadId' , i ) as string ;
const updateFields = this . getNodeParameter ( 'updateFields' , i ) as IDataObject ;
const body : ILead = { } ;
if ( ! Object . keys ( updateFields ) . length ) {
throw new Error ( 'You must add at least one update field' ) ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . lastname !== undefined ) {
2020-02-10 12:55:28 -08:00
body . LastName = updateFields . lastname as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . company !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Company = updateFields . company as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . email !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Email = updateFields . email as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . city !== undefined ) {
2020-02-10 12:55:28 -08:00
body . City = updateFields . city as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . phone !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Phone = updateFields . phone as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . state !== undefined ) {
2020-02-10 12:55:28 -08:00
body . State = updateFields . state as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . title !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Title = updateFields . title as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . jigsaw !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Jigsaw = updateFields . jigsaw as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . rating !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Rating = updateFields . rating as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . status !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Status = updateFields . status as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . street !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Street = updateFields . street as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . country !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Country = updateFields . country as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . owner !== undefined ) {
2020-02-10 12:55:28 -08:00
body . OwnerId = updateFields . owner as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . website !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Website = updateFields . website as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . industry !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Industry = updateFields . industry as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . firstName !== undefined ) {
2020-02-10 12:55:28 -08:00
body . FirstName = updateFields . firstName as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . leadSource !== undefined ) {
2020-02-10 12:55:28 -08:00
body . LeadSource = updateFields . leadSource as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . postalCode !== undefined ) {
2020-02-10 12:55:28 -08:00
body . PostalCode = updateFields . postalCode as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . salutation !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Salutation = updateFields . salutation as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . description !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Description = updateFields . description as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . annualRevenue !== undefined ) {
2020-02-10 12:55:28 -08:00
body . AnnualRevenue = updateFields . annualRevenue as number ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . isUnreadByOwner !== undefined ) {
2020-02-10 12:55:28 -08:00
body . IsUnreadByOwner = updateFields . isUnreadByOwner as boolean ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . numberOfEmployees !== undefined ) {
2020-02-10 12:55:28 -08:00
body . NumberOfEmployees = updateFields . numberOfEmployees as number ;
}
responseData = await salesforceApiRequest . call ( this , 'PATCH' , ` /sobjects/lead/ ${ leadId } ` , body ) ;
}
//https://developer.salesforce.com/docs/api-explorer/sobject/Lead/get-lead-id
if ( operation === 'get' ) {
const leadId = this . getNodeParameter ( 'leadId' , i ) as string ;
responseData = await salesforceApiRequest . call ( this , 'GET' , ` /sobjects/lead/ ${ leadId } ` ) ;
}
//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 ;
2020-02-12 22:35:56 -08:00
const fields = [ 'id,company,firstname,lastname,street,postalCode,city,email,status' ] ;
2020-02-10 12:55:28 -08:00
if ( options . fields ) {
// @ts-ignore
2020-02-12 22:35:56 -08:00
fields . push ( . . . options . fields . split ( ',' ) ) ;
2020-02-10 12:55:28 -08:00
}
try {
if ( returnAll ) {
2020-07-30 02:35:36 -07:00
qs . q = ` SELECT ${ fields . join ( ',' ) } FROM Lead ` ;
2020-02-10 12:55:28 -08:00
responseData = await salesforceApiRequestAllItems . call ( this , 'records' , 'GET' , '/query' , { } , qs ) ;
} else {
const limit = this . getNodeParameter ( 'limit' , i ) as number ;
qs . q = ` SELECT ${ fields . join ( ',' ) } FROM Lead Limit ${ limit } ` ;
responseData = await salesforceApiRequestAllItems . call ( this , 'records' , 'GET' , '/query' , { } , qs ) ;
}
} catch ( err ) {
throw new Error ( ` Salesforce Error: ${ err } ` ) ;
}
}
//https://developer.salesforce.com/docs/api-explorer/sobject/Lead/delete-lead-id
if ( operation === 'delete' ) {
const leadId = this . getNodeParameter ( 'leadId' , i ) as string ;
try {
responseData = await salesforceApiRequest . call ( this , 'DELETE' , ` /sobjects/lead/ ${ leadId } ` ) ;
} catch ( err ) {
throw new Error ( ` Salesforce Error: ${ err } ` ) ;
}
}
//https://developer.salesforce.com/docs/api-explorer/sobject/Lead/get-lead
if ( operation === 'getSummary' ) {
responseData = await salesforceApiRequest . call ( this , 'GET' , '/sobjects/lead' ) ;
}
//https://developer.salesforce.com/docs/api-explorer/sobject/CampaignMember
if ( operation === 'addToCampaign' ) {
const leadId = this . getNodeParameter ( 'leadId' , i ) as string ;
const campaignId = this . getNodeParameter ( 'campaignId' , i ) as string ;
const options = this . getNodeParameter ( 'options' , i ) as IDataObject ;
const body : ICampaignMember = {
LeadId : leadId ,
CampaignId : campaignId ,
} ;
if ( options . status ) {
body . Status = options . status as string ;
}
responseData = await salesforceApiRequest . call ( this , 'POST' , '/sobjects/CampaignMember' , body ) ;
}
//https://developer.salesforce.com/docs/api-explorer/sobject/Note/post-note
if ( operation === 'addNote' ) {
const leadId = this . getNodeParameter ( 'leadId' , i ) as string ;
const title = this . getNodeParameter ( 'title' , i ) as string ;
const options = this . getNodeParameter ( 'options' , i ) as IDataObject ;
const body : INote = {
Title : title ,
ParentId : leadId ,
} ;
if ( options . body ) {
body . Body = options . body as string ;
}
if ( options . owner ) {
body . OwnerId = options . owner as string ;
}
if ( options . isPrivate ) {
body . IsPrivate = options . isPrivate as boolean ;
}
responseData = await salesforceApiRequest . call ( this , 'POST' , '/sobjects/note' , body ) ;
}
}
if ( resource === 'contact' ) {
//https://developer.salesforce.com/docs/api-explorer/sobject/Contact/post-contact
if ( operation === 'create' ) {
const lastname = this . getNodeParameter ( 'lastname' , i ) as string ;
const additionalFields = this . getNodeParameter ( 'additionalFields' , i ) as IDataObject ;
const body : IContact = {
LastName : lastname ,
} ;
2020-08-26 23:16:50 -07:00
if ( additionalFields . fax !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Fax = additionalFields . fax as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . email !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Email = additionalFields . email as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . phone !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Phone = additionalFields . phone as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . title !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Title = additionalFields . title as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . jigsaw !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Jigsaw = additionalFields . jigsaw as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . owner !== undefined ) {
2020-02-10 12:55:28 -08:00
body . OwnerId = additionalFields . owner as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . acconuntId !== undefined ) {
2020-02-10 12:55:28 -08:00
body . AccountId = additionalFields . acconuntId as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . birthdate !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Birthdate = additionalFields . birthdate as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . firstName !== undefined ) {
2020-02-10 12:55:28 -08:00
body . FirstName = additionalFields . firstName as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . homePhone !== undefined ) {
2020-02-10 12:55:28 -08:00
body . HomePhone = additionalFields . homePhone as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . otherCity !== undefined ) {
2020-02-10 12:55:28 -08:00
body . OtherCity = additionalFields . otherCity as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . department !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Department = additionalFields . department as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . leadSource !== undefined ) {
2020-02-10 12:55:28 -08:00
body . LeadSource = additionalFields . leadSource as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . otherPhone !== undefined ) {
2020-02-10 12:55:28 -08:00
body . OtherPhone = additionalFields . otherPhone as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . otherState !== undefined ) {
2020-02-10 12:55:28 -08:00
body . OtherState = additionalFields . otherState as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . salutation !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Salutation = additionalFields . salutation as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . description !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Description = additionalFields . description as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . mailingCity !== undefined ) {
2020-02-10 12:55:28 -08:00
body . MailingCity = additionalFields . mailingCity as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . mobilePhone !== undefined ) {
2020-02-10 12:55:28 -08:00
body . MobilePhone = additionalFields . mobilePhone as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . otherStreet !== undefined ) {
2020-02-10 12:55:28 -08:00
body . OtherStreet = additionalFields . otherStreet as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . mailingState !== undefined ) {
2020-02-10 12:55:28 -08:00
body . MailingState = additionalFields . mailingState as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . otherCountry !== undefined ) {
2020-02-10 12:55:28 -08:00
body . OtherCountry = additionalFields . otherCountry as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . assistantName !== undefined ) {
2020-02-10 12:55:28 -08:00
body . AssistantName = additionalFields . assistantName as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . mailingStreet !== undefined ) {
2020-02-10 12:55:28 -08:00
body . MailingStreet = additionalFields . mailingStreet as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . assistantPhone !== undefined ) {
2020-02-10 12:55:28 -08:00
body . AssistantPhone = additionalFields . assistantPhone as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . mailingCountry !== undefined ) {
2020-02-10 12:55:28 -08:00
body . MailingCountry = additionalFields . mailingCountry as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . otherPostalCode !== undefined ) {
2020-02-10 12:55:28 -08:00
body . OtherPostalCode = additionalFields . otherPostalCode as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . emailBouncedDate !== undefined ) {
2020-02-10 12:55:28 -08:00
body . EmailBouncedDate = additionalFields . emailBouncedDate as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . mailingPostalCode !== undefined ) {
2020-02-10 12:55:28 -08:00
body . MailingPostalCode = additionalFields . mailingPostalCode as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . emailBouncedReason !== undefined ) {
2020-02-10 12:55:28 -08:00
body . EmailBouncedReason = additionalFields . emailBouncedReason as string ;
}
responseData = await salesforceApiRequest . call ( this , 'POST' , '/sobjects/contact' , body ) ;
}
//https://developer.salesforce.com/docs/api-explorer/sobject/Contact/patch-contact-id
if ( operation === 'update' ) {
const contactId = this . getNodeParameter ( 'contactId' , i ) as string ;
const updateFields = this . getNodeParameter ( 'updateFields' , i ) as IDataObject ;
const body : IContact = { } ;
if ( ! Object . keys ( updateFields ) . length ) {
throw new Error ( 'You must add at least one update field' ) ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . fax !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Fax = updateFields . fax as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . email !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Email = updateFields . email as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . phone !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Phone = updateFields . phone as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . title !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Title = updateFields . title as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . jigsaw !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Jigsaw = updateFields . jigsaw as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . owner !== undefined ) {
2020-02-10 12:55:28 -08:00
body . OwnerId = updateFields . owner as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . acconuntId !== undefined ) {
2020-02-10 12:55:28 -08:00
body . AccountId = updateFields . acconuntId as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . birthdate !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Birthdate = updateFields . birthdate as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . firstName !== undefined ) {
2020-02-10 12:55:28 -08:00
body . FirstName = updateFields . firstName as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . homePhone !== undefined ) {
2020-02-10 12:55:28 -08:00
body . HomePhone = updateFields . homePhone as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . otherCity !== undefined ) {
2020-02-10 12:55:28 -08:00
body . OtherCity = updateFields . otherCity as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . department !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Department = updateFields . department as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . leadSource !== undefined ) {
2020-02-10 12:55:28 -08:00
body . LeadSource = updateFields . leadSource as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . otherPhone !== undefined ) {
2020-02-10 12:55:28 -08:00
body . OtherPhone = updateFields . otherPhone as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . otherState !== undefined ) {
2020-02-10 12:55:28 -08:00
body . OtherState = updateFields . otherState as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . salutation !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Salutation = updateFields . salutation as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . description !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Description = updateFields . description as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . mailingCity !== undefined ) {
2020-02-10 12:55:28 -08:00
body . MailingCity = updateFields . mailingCity as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . mobilePhone !== undefined ) {
2020-02-10 12:55:28 -08:00
body . MobilePhone = updateFields . mobilePhone as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . otherStreet !== undefined ) {
2020-02-10 12:55:28 -08:00
body . OtherStreet = updateFields . otherStreet as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . mailingState !== undefined ) {
2020-02-10 12:55:28 -08:00
body . MailingState = updateFields . mailingState as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . otherCountry !== undefined ) {
2020-02-10 12:55:28 -08:00
body . OtherCountry = updateFields . otherCountry as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . assistantName !== undefined ) {
2020-02-10 12:55:28 -08:00
body . AssistantName = updateFields . assistantName as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . mailingStreet !== undefined ) {
2020-02-10 12:55:28 -08:00
body . MailingStreet = updateFields . mailingStreet as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . assistantPhone !== undefined ) {
2020-02-10 12:55:28 -08:00
body . AssistantPhone = updateFields . assistantPhone as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . mailingCountry !== undefined ) {
2020-02-10 12:55:28 -08:00
body . MailingCountry = updateFields . mailingCountry as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . otherPostalCode !== undefined ) {
2020-02-10 12:55:28 -08:00
body . OtherPostalCode = updateFields . otherPostalCode as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . emailBouncedDate !== undefined ) {
2020-02-10 12:55:28 -08:00
body . EmailBouncedDate = updateFields . emailBouncedDate as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . mailingPostalCode !== undefined ) {
2020-02-10 12:55:28 -08:00
body . MailingPostalCode = updateFields . mailingPostalCode as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . emailBouncedReason !== undefined ) {
2020-02-10 12:55:28 -08:00
body . EmailBouncedReason = updateFields . emailBouncedReason as string ;
}
responseData = await salesforceApiRequest . call ( this , 'PATCH' , ` /sobjects/contact/ ${ contactId } ` , body ) ;
}
//https://developer.salesforce.com/docs/api-explorer/sobject/Contact/get-contact-id
if ( operation === 'get' ) {
const contactId = this . getNodeParameter ( 'contactId' , i ) as string ;
responseData = await salesforceApiRequest . call ( this , 'GET' , ` /sobjects/contact/ ${ contactId } ` ) ;
}
//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 ;
2020-02-12 22:35:56 -08:00
const fields = [ 'id,firstname,lastname,email' ] ;
2020-02-10 12:55:28 -08:00
if ( options . fields ) {
// @ts-ignore
2020-02-12 22:35:56 -08:00
fields . push ( . . . options . fields . split ( ',' ) ) ;
2020-02-10 12:55:28 -08:00
}
try {
if ( returnAll ) {
2020-07-30 02:35:36 -07:00
qs . q = ` SELECT ${ fields . join ( ',' ) } FROM Contact ` ;
2020-02-10 12:55:28 -08:00
responseData = await salesforceApiRequestAllItems . call ( this , 'records' , 'GET' , '/query' , { } , qs ) ;
} else {
const limit = this . getNodeParameter ( 'limit' , i ) as number ;
qs . q = ` SELECT ${ fields . join ( ',' ) } FROM Contact Limit ${ limit } ` ;
responseData = await salesforceApiRequestAllItems . call ( this , 'records' , 'GET' , '/query' , { } , qs ) ;
}
} catch ( err ) {
throw new Error ( ` Salesforce Error: ${ err } ` ) ;
}
}
//https://developer.salesforce.com/docs/api-explorer/sobject/Contact/delete-contact-id
if ( operation === 'delete' ) {
const contactId = this . getNodeParameter ( 'contactId' , i ) as string ;
try {
responseData = await salesforceApiRequest . call ( this , 'DELETE' , ` /sobjects/contact/ ${ contactId } ` ) ;
} catch ( err ) {
throw new Error ( ` Salesforce Error: ${ err } ` ) ;
}
}
//https://developer.salesforce.com/docs/api-explorer/sobject/Contact/get-contact
if ( operation === 'getSummary' ) {
responseData = await salesforceApiRequest . call ( this , 'GET' , '/sobjects/contact' ) ;
}
//https://developer.salesforce.com/docs/api-explorer/sobject/CampaignMember
if ( operation === 'addToCampaign' ) {
const contactId = this . getNodeParameter ( 'contactId' , i ) as string ;
const campaignId = this . getNodeParameter ( 'campaignId' , i ) as string ;
const options = this . getNodeParameter ( 'options' , i ) as IDataObject ;
const body : ICampaignMember = {
ContactId : contactId ,
CampaignId : campaignId ,
} ;
if ( options . status ) {
body . Status = options . status as string ;
}
responseData = await salesforceApiRequest . call ( this , 'POST' , '/sobjects/CampaignMember' , body ) ;
}
//https://developer.salesforce.com/docs/api-explorer/sobject/Note/post-note
if ( operation === 'addNote' ) {
const contactId = this . getNodeParameter ( 'contactId' , i ) as string ;
const title = this . getNodeParameter ( 'title' , i ) as string ;
const options = this . getNodeParameter ( 'options' , i ) as IDataObject ;
const body : INote = {
Title : title ,
ParentId : contactId ,
} ;
2020-08-26 23:16:50 -07:00
if ( options . body !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Body = options . body as string ;
}
2020-08-26 23:16:50 -07:00
if ( options . owner !== undefined ) {
2020-02-10 12:55:28 -08:00
body . OwnerId = options . owner as string ;
}
2020-08-26 23:16:50 -07:00
if ( options . isPrivate !== undefined ) {
2020-02-10 12:55:28 -08:00
body . IsPrivate = options . isPrivate as boolean ;
}
responseData = await salesforceApiRequest . call ( this , 'POST' , '/sobjects/note' , body ) ;
}
}
if ( resource === 'opportunity' ) {
//https://developer.salesforce.com/docs/api-explorer/sobject/Opportunity/post-opportunity
if ( operation === 'create' ) {
const name = this . getNodeParameter ( 'name' , i ) as string ;
const closeDate = this . getNodeParameter ( 'closeDate' , i ) as string ;
const stageName = this . getNodeParameter ( 'stageName' , i ) as string ;
const additionalFields = this . getNodeParameter ( 'additionalFields' , i ) as IDataObject ;
const body : IOpportunity = {
Name : name ,
CloseDate : closeDate ,
StageName : stageName ,
} ;
2020-08-26 23:16:50 -07:00
if ( additionalFields . type !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Type = additionalFields . type as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . ammount !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Amount = additionalFields . ammount as number ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . owner !== undefined ) {
2020-02-10 12:55:28 -08:00
body . OwnerId = additionalFields . owner as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . nextStep !== undefined ) {
2020-02-10 12:55:28 -08:00
body . NextStep = additionalFields . nextStep as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . accountId !== undefined ) {
2020-02-10 12:55:28 -08:00
body . AccountId = additionalFields . accountId as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . campaignId !== undefined ) {
2020-02-10 12:55:28 -08:00
body . CampaignId = additionalFields . campaignId as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . leadSource !== undefined ) {
2020-02-10 12:55:28 -08:00
body . LeadSource = additionalFields . leadSource as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . description !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Description = additionalFields . description as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . probability !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Probability = additionalFields . probability as number ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . pricebook2Id !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Pricebook2Id = additionalFields . pricebook2Id as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . forecastCategoryName !== undefined ) {
2020-02-10 12:55:28 -08:00
body . ForecastCategoryName = additionalFields . forecastCategoryName as string ;
}
responseData = await salesforceApiRequest . call ( this , 'POST' , '/sobjects/opportunity' , body ) ;
}
//https://developer.salesforce.com/docs/api-explorer/sobject/Opportunity/post-opportunity
if ( operation === 'update' ) {
const opportunityId = this . getNodeParameter ( 'opportunityId' , i ) as string ;
const updateFields = this . getNodeParameter ( 'updateFields' , i ) as IDataObject ;
const body : IOpportunity = { } ;
2020-08-26 23:16:50 -07:00
if ( updateFields . name !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Name = updateFields . name as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . closeDate !== undefined ) {
2020-02-10 12:55:28 -08:00
body . CloseDate = updateFields . closeDate as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . stageName !== undefined ) {
2020-02-10 12:55:28 -08:00
body . StageName = updateFields . stageName as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . type !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Type = updateFields . type as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . ammount !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Amount = updateFields . ammount as number ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . owner !== undefined ) {
2020-02-10 12:55:28 -08:00
body . OwnerId = updateFields . owner as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . nextStep !== undefined ) {
2020-02-10 12:55:28 -08:00
body . NextStep = updateFields . nextStep as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . accountId !== undefined ) {
2020-02-10 12:55:28 -08:00
body . AccountId = updateFields . accountId as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . campaignId !== undefined ) {
2020-02-10 12:55:28 -08:00
body . CampaignId = updateFields . campaignId as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . leadSource !== undefined ) {
2020-02-10 12:55:28 -08:00
body . LeadSource = updateFields . leadSource as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . description !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Description = updateFields . description as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . probability !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Probability = updateFields . probability as number ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . pricebook2Id !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Pricebook2Id = updateFields . pricebook2Id as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . forecastCategoryName !== undefined ) {
2020-02-10 12:55:28 -08:00
body . ForecastCategoryName = updateFields . forecastCategoryName as string ;
}
responseData = await salesforceApiRequest . call ( this , 'PATCH' , ` /sobjects/opportunity/ ${ opportunityId } ` , body ) ;
}
//https://developer.salesforce.com/docs/api-explorer/sobject/Opportunity/get-opportunity-id
if ( operation === 'get' ) {
const opportunityId = this . getNodeParameter ( 'opportunityId' , i ) as string ;
responseData = await salesforceApiRequest . call ( this , 'GET' , ` /sobjects/opportunity/ ${ opportunityId } ` ) ;
}
//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 ;
2020-02-12 22:35:56 -08:00
const fields = [ 'id,accountId,amount,probability,type' ] ;
2020-02-10 12:55:28 -08:00
if ( options . fields ) {
// @ts-ignore
2020-02-12 22:35:56 -08:00
fields . push ( . . . options . fields . split ( ',' ) ) ;
2020-02-10 12:55:28 -08:00
}
try {
if ( returnAll ) {
2020-07-30 02:35:36 -07:00
qs . q = ` SELECT ${ fields . join ( ',' ) } FROM Opportunity ` ;
2020-02-10 12:55:28 -08:00
responseData = await salesforceApiRequestAllItems . call ( this , 'records' , 'GET' , '/query' , { } , qs ) ;
} else {
const limit = this . getNodeParameter ( 'limit' , i ) as number ;
qs . q = ` SELECT ${ fields . join ( ',' ) } FROM Opportunity Limit ${ limit } ` ;
responseData = await salesforceApiRequestAllItems . call ( this , 'records' , 'GET' , '/query' , { } , qs ) ;
}
} catch ( err ) {
throw new Error ( ` Salesforce Error: ${ err } ` ) ;
}
}
//https://developer.salesforce.com/docs/api-explorer/sobject/Opportunity/delete-opportunity-id
if ( operation === 'delete' ) {
const opportunityId = this . getNodeParameter ( 'opportunityId' , i ) as string ;
try {
responseData = await salesforceApiRequest . call ( this , 'DELETE' , ` /sobjects/opportunity/ ${ opportunityId } ` ) ;
} catch ( err ) {
throw new Error ( ` Salesforce Error: ${ err } ` ) ;
}
}
//https://developer.salesforce.com/docs/api-explorer/sobject/Opportunity/get-opportunity
if ( operation === 'getSummary' ) {
responseData = await salesforceApiRequest . call ( this , 'GET' , '/sobjects/opportunity' ) ;
}
//https://developer.salesforce.com/docs/api-explorer/sobject/Note/post-note
if ( operation === 'addNote' ) {
const opportunityId = this . getNodeParameter ( 'opportunityId' , i ) as string ;
const title = this . getNodeParameter ( 'title' , i ) as string ;
const options = this . getNodeParameter ( 'options' , i ) as IDataObject ;
const body : INote = {
Title : title ,
ParentId : opportunityId ,
} ;
2020-08-26 23:16:50 -07:00
if ( options . body !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Body = options . body as string ;
}
2020-08-26 23:16:50 -07:00
if ( options . owner !== undefined ) {
2020-02-10 12:55:28 -08:00
body . OwnerId = options . owner as string ;
}
2020-08-26 23:16:50 -07:00
if ( options . isPrivate !== undefined ) {
2020-02-10 12:55:28 -08:00
body . IsPrivate = options . isPrivate as boolean ;
}
responseData = await salesforceApiRequest . call ( this , 'POST' , '/sobjects/note' , body ) ;
}
}
if ( resource === 'account' ) {
//https://developer.salesforce.com/docs/api-explorer/sobject/Account/post-account
if ( operation === 'create' ) {
const name = this . getNodeParameter ( 'name' , i ) as string ;
const additionalFields = this . getNodeParameter ( 'additionalFields' , i ) as IDataObject ;
const body : IAccount = {
Name : name ,
} ;
2020-08-26 23:16:50 -07:00
if ( additionalFields . fax !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Fax = additionalFields . fax as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . type !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Type = additionalFields . type as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . jigsaw !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Jigsaw = additionalFields . jigsaw as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . phone !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Phone = additionalFields . phone as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . owner !== undefined ) {
2020-02-10 12:55:28 -08:00
body . OwnerId = additionalFields . owner as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . sicDesc !== undefined ) {
2020-02-10 12:55:28 -08:00
body . SicDesc = additionalFields . sicDesc as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . website !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Website = additionalFields . website as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . industry !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Industry = additionalFields . industry as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . parentId !== undefined ) {
2020-02-10 12:55:28 -08:00
body . ParentId = additionalFields . parentId as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . billingCity !== undefined ) {
2020-02-10 12:55:28 -08:00
body . BillingCity = additionalFields . billingCity as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . description !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Description = additionalFields . description as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . billingState !== undefined ) {
2020-02-10 12:55:28 -08:00
body . BillingState = additionalFields . billingState as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . shippingCity !== undefined ) {
2020-02-10 12:55:28 -08:00
body . ShippingCity = additionalFields . shippingCity as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . accountSource !== undefined ) {
2020-02-10 12:55:28 -08:00
body . AccountSource = additionalFields . accountSource as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . annualRevenue !== undefined ) {
2020-02-10 12:55:28 -08:00
body . AnnualRevenue = additionalFields . annualRevenue as number ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . billingStreet !== undefined ) {
2020-02-10 12:55:28 -08:00
body . BillingStreet = additionalFields . billingStreet as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . shippingState !== undefined ) {
2020-02-10 12:55:28 -08:00
body . ShippingState = additionalFields . shippingState as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . billingCountry !== undefined ) {
2020-02-10 12:55:28 -08:00
body . BillingCountry = additionalFields . billingCountry as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . shippingStreet !== undefined ) {
2020-02-10 12:55:28 -08:00
body . ShippingStreet = additionalFields . shippingStreet as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . shippingCountry !== undefined ) {
2020-02-10 12:55:28 -08:00
body . ShippingCountry = additionalFields . shippingCountry as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . billingPostalCode !== undefined ) {
2020-02-10 12:55:28 -08:00
body . BillingPostalCode = additionalFields . billingPostalCode as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . numberOfEmployees !== undefined ) {
2020-02-10 12:55:28 -08:00
body . NumberOfEmployees = additionalFields . numberOfEmployees as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . shippingPostalCode !== undefined ) {
2020-02-10 12:55:28 -08:00
body . ShippingPostalCode = additionalFields . shippingPostalCode as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . shippingPostalCode !== undefined ) {
2020-02-10 12:55:28 -08:00
body . ShippingPostalCode = additionalFields . shippingPostalCode as string ;
}
responseData = await salesforceApiRequest . call ( this , 'POST' , '/sobjects/account' , body ) ;
}
//https://developer.salesforce.com/docs/api-explorer/sobject/Account/patch-account-id
if ( operation === 'update' ) {
const accountId = this . getNodeParameter ( 'accountId' , i ) as string ;
const updateFields = this . getNodeParameter ( 'updateFields' , i ) as IDataObject ;
const body : IAccount = { } ;
2020-08-26 23:16:50 -07:00
if ( updateFields . name !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Name = updateFields . name as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . fax !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Fax = updateFields . fax as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . type !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Type = updateFields . type as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . jigsaw !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Jigsaw = updateFields . jigsaw as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . phone !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Phone = updateFields . phone as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . owner !== undefined ) {
2020-02-10 12:55:28 -08:00
body . OwnerId = updateFields . owner as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . sicDesc !== undefined ) {
2020-02-10 12:55:28 -08:00
body . SicDesc = updateFields . sicDesc as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . website !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Website = updateFields . website as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . industry !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Industry = updateFields . industry as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . parentId !== undefined ) {
2020-02-10 12:55:28 -08:00
body . ParentId = updateFields . parentId as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . billingCity !== undefined ) {
2020-02-10 12:55:28 -08:00
body . BillingCity = updateFields . billingCity as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . description !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Description = updateFields . description as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . billingState !== undefined ) {
2020-02-10 12:55:28 -08:00
body . BillingState = updateFields . billingState as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . shippingCity !== undefined ) {
2020-02-10 12:55:28 -08:00
body . ShippingCity = updateFields . shippingCity as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . accountSource !== undefined ) {
2020-02-10 12:55:28 -08:00
body . AccountSource = updateFields . accountSource as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . annualRevenue !== undefined ) {
2020-02-10 12:55:28 -08:00
body . AnnualRevenue = updateFields . annualRevenue as number ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . billingStreet !== undefined ) {
2020-02-10 12:55:28 -08:00
body . BillingStreet = updateFields . billingStreet as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . shippingState !== undefined ) {
2020-02-10 12:55:28 -08:00
body . ShippingState = updateFields . shippingState as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . billingCountry !== undefined ) {
2020-02-10 12:55:28 -08:00
body . BillingCountry = updateFields . billingCountry as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . shippingStreet !== undefined ) {
2020-02-10 12:55:28 -08:00
body . ShippingStreet = updateFields . shippingStreet as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . shippingCountry !== undefined ) {
2020-02-10 12:55:28 -08:00
body . ShippingCountry = updateFields . shippingCountry as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . billingPostalCode !== undefined ) {
2020-02-10 12:55:28 -08:00
body . BillingPostalCode = updateFields . billingPostalCode as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . numberOfEmployees !== undefined ) {
2020-02-10 12:55:28 -08:00
body . NumberOfEmployees = updateFields . numberOfEmployees as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . shippingPostalCode !== undefined ) {
2020-02-10 12:55:28 -08:00
body . ShippingPostalCode = updateFields . shippingPostalCode as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . shippingPostalCode !== undefined ) {
2020-02-10 12:55:28 -08:00
body . ShippingPostalCode = updateFields . shippingPostalCode as string ;
}
responseData = await salesforceApiRequest . call ( this , 'PATCH' , ` /sobjects/account/ ${ accountId } ` , body ) ;
}
//https://developer.salesforce.com/docs/api-explorer/sobject/Account/get-account-id
if ( operation === 'get' ) {
const accountId = this . getNodeParameter ( 'accountId' , i ) as string ;
responseData = await salesforceApiRequest . call ( this , 'GET' , ` /sobjects/account/ ${ accountId } ` ) ;
}
//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 ;
2020-02-12 22:35:56 -08:00
const fields = [ 'id,name,type' ] ;
2020-02-10 12:55:28 -08:00
if ( options . fields ) {
// @ts-ignore
2020-02-12 22:35:56 -08:00
fields . push ( . . . options . fields . split ( ',' ) ) ;
2020-02-10 12:55:28 -08:00
}
try {
if ( returnAll ) {
2020-07-30 02:35:36 -07:00
qs . q = ` SELECT ${ fields . join ( ',' ) } FROM Account ` ;
2020-02-10 12:55:28 -08:00
responseData = await salesforceApiRequestAllItems . call ( this , 'records' , 'GET' , '/query' , { } , qs ) ;
} else {
const limit = this . getNodeParameter ( 'limit' , i ) as number ;
qs . q = ` SELECT ${ fields . join ( ',' ) } FROM Account Limit ${ limit } ` ;
responseData = await salesforceApiRequestAllItems . call ( this , 'records' , 'GET' , '/query' , { } , qs ) ;
}
} catch ( err ) {
throw new Error ( ` Salesforce Error: ${ err } ` ) ;
}
}
//https://developer.salesforce.com/docs/api-explorer/sobject/Account/delete-account-id
if ( operation === 'delete' ) {
const accountId = this . getNodeParameter ( 'accountId' , i ) as string ;
try {
responseData = await salesforceApiRequest . call ( this , 'DELETE' , ` /sobjects/account/ ${ accountId } ` ) ;
} catch ( err ) {
throw new Error ( ` Salesforce Error: ${ err } ` ) ;
}
}
//https://developer.salesforce.com/docs/api-explorer/sobject/Account/get-account
if ( operation === 'getSummary' ) {
responseData = await salesforceApiRequest . call ( this , 'GET' , '/sobjects/account' ) ;
}
//https://developer.salesforce.com/docs/api-explorer/sobject/Note/post-note
if ( operation === 'addNote' ) {
const accountId = this . getNodeParameter ( 'accountId' , i ) as string ;
const title = this . getNodeParameter ( 'title' , i ) as string ;
const options = this . getNodeParameter ( 'options' , i ) as IDataObject ;
const body : INote = {
Title : title ,
ParentId : accountId ,
} ;
2020-08-26 23:16:50 -07:00
if ( options . body !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Body = options . body as string ;
}
2020-08-26 23:16:50 -07:00
if ( options . owner !== undefined ) {
2020-02-10 12:55:28 -08:00
body . OwnerId = options . owner as string ;
}
2020-08-26 23:16:50 -07:00
if ( options . isPrivate !== undefined ) {
2020-02-10 12:55:28 -08:00
body . IsPrivate = options . isPrivate as boolean ;
}
responseData = await salesforceApiRequest . call ( this , 'POST' , '/sobjects/note' , body ) ;
}
}
if ( resource === 'case' ) {
//https://developer.salesforce.com/docs/api-explorer/sobject/Case/post-case
if ( operation === 'create' ) {
const type = this . getNodeParameter ( 'type' , i ) as string ;
const additionalFields = this . getNodeParameter ( 'additionalFields' , i ) as IDataObject ;
const body : ICase = {
Type : type ,
} ;
2020-08-26 23:16:50 -07:00
if ( additionalFields . origin !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Origin = additionalFields . origin as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . reason !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Reason = additionalFields . reason as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . owner !== undefined ) {
2020-02-10 12:55:28 -08:00
body . OwnerId = additionalFields . owner as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . subject !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Subject = additionalFields . subject as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . parentId !== undefined ) {
2020-02-10 12:55:28 -08:00
body . ParentId = additionalFields . parentId as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . priority !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Priority = additionalFields . priority as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . accountId !== undefined ) {
2020-02-10 12:55:28 -08:00
body . AccountId = additionalFields . accountId as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . contactId !== undefined ) {
2020-02-10 12:55:28 -08:00
body . ContactId = additionalFields . contactId as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . description !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Description = additionalFields . description as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . isEscalated !== undefined ) {
2020-02-10 12:55:28 -08:00
body . IsEscalated = additionalFields . isEscalated as boolean ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . suppliedName !== undefined ) {
2020-02-10 12:55:28 -08:00
body . SuppliedName = additionalFields . suppliedName as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . suppliedEmail !== undefined ) {
2020-02-10 12:55:28 -08:00
body . SuppliedEmail = additionalFields . suppliedEmail as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . suppliedPhone !== undefined ) {
2020-02-10 12:55:28 -08:00
body . SuppliedPhone = additionalFields . suppliedPhone as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . suppliedCompany !== undefined ) {
2020-02-10 12:55:28 -08:00
body . SuppliedCompany = additionalFields . suppliedCompany as string ;
}
responseData = await salesforceApiRequest . call ( this , 'POST' , '/sobjects/case' , body ) ;
}
//https://developer.salesforce.com/docs/api-explorer/sobject/Case/patch-case-id
if ( operation === 'update' ) {
const caseId = this . getNodeParameter ( 'caseId' , i ) as string ;
const updateFields = this . getNodeParameter ( 'updateFields' , i ) as IDataObject ;
const body : ICase = { } ;
2020-08-26 23:16:50 -07:00
if ( updateFields . type !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Type = updateFields . type as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . origin !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Origin = updateFields . origin as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . reason !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Reason = updateFields . reason as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . owner !== undefined ) {
2020-02-10 12:55:28 -08:00
body . OwnerId = updateFields . owner as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . subject !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Subject = updateFields . subject as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . parentId !== undefined ) {
2020-02-10 12:55:28 -08:00
body . ParentId = updateFields . parentId as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . priority !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Priority = updateFields . priority as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . accountId !== undefined ) {
2020-02-10 12:55:28 -08:00
body . AccountId = updateFields . accountId as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . contactId !== undefined ) {
2020-02-10 12:55:28 -08:00
body . ContactId = updateFields . contactId as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . description !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Description = updateFields . description as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . isEscalated !== undefined ) {
2020-02-10 12:55:28 -08:00
body . IsEscalated = updateFields . isEscalated as boolean ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . suppliedName !== undefined ) {
2020-02-10 12:55:28 -08:00
body . SuppliedName = updateFields . suppliedName as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . suppliedEmail !== undefined ) {
2020-02-10 12:55:28 -08:00
body . SuppliedEmail = updateFields . suppliedEmail as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . suppliedPhone !== undefined ) {
2020-02-10 12:55:28 -08:00
body . SuppliedPhone = updateFields . suppliedPhone as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . suppliedCompany !== undefined ) {
2020-02-10 12:55:28 -08:00
body . SuppliedCompany = updateFields . suppliedCompany as string ;
}
responseData = await salesforceApiRequest . call ( this , 'PATCH' , ` /sobjects/case/ ${ caseId } ` , body ) ;
}
//https://developer.salesforce.com/docs/api-explorer/sobject/Case/get-case-id
if ( operation === 'get' ) {
const caseId = this . getNodeParameter ( 'caseId' , i ) as string ;
responseData = await salesforceApiRequest . call ( this , 'GET' , ` /sobjects/case/ ${ caseId } ` ) ;
}
//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 ;
2020-02-12 22:35:56 -08:00
const fields = [ 'id,accountId,contactId,priority,status,subject,type' ] ;
2020-02-10 12:55:28 -08:00
if ( options . fields ) {
// @ts-ignore
2020-02-12 22:35:56 -08:00
fields . push ( . . . options . fields . split ( ',' ) ) ;
2020-02-10 12:55:28 -08:00
}
try {
if ( returnAll ) {
2020-07-30 02:35:36 -07:00
qs . q = ` SELECT ${ fields . join ( ',' ) } FROM Case ` ;
2020-02-10 12:55:28 -08:00
responseData = await salesforceApiRequestAllItems . call ( this , 'records' , 'GET' , '/query' , { } , qs ) ;
} else {
const limit = this . getNodeParameter ( 'limit' , i ) as number ;
qs . q = ` SELECT ${ fields . join ( ',' ) } FROM Case Limit ${ limit } ` ;
responseData = await salesforceApiRequestAllItems . call ( this , 'records' , 'GET' , '/query' , { } , qs ) ;
}
} catch ( err ) {
throw new Error ( ` Salesforce Error: ${ err } ` ) ;
}
}
//https://developer.salesforce.com/docs/api-explorer/sobject/Case/delete-case-id
if ( operation === 'delete' ) {
const caseId = this . getNodeParameter ( 'caseId' , i ) as string ;
try {
responseData = await salesforceApiRequest . call ( this , 'DELETE' , ` /sobjects/case/ ${ caseId } ` ) ;
} catch ( err ) {
throw new Error ( ` Salesforce Error: ${ err } ` ) ;
}
}
//https://developer.salesforce.com/docs/api-explorer/sobject/Case/get-case
if ( operation === 'getSummary' ) {
responseData = await salesforceApiRequest . call ( this , 'GET' , '/sobjects/case' ) ;
}
//https://developer.salesforce.com/docs/api-explorer/sobject/CaseComment/post-casecomment
if ( operation === 'addComment' ) {
const caseId = this . getNodeParameter ( 'caseId' , i ) as string ;
const options = this . getNodeParameter ( 'options' , i ) as IDataObject ;
const body : ICaseComment = {
ParentId : caseId ,
} ;
2020-08-26 23:16:50 -07:00
if ( options . commentBody !== undefined ) {
2020-02-10 12:55:28 -08:00
body . CommentBody = options . commentBody as string ;
}
2020-08-26 23:16:50 -07:00
if ( options . isPublished !== undefined ) {
2020-02-10 12:55:28 -08:00
body . IsPublished = options . isPublished as boolean ;
}
responseData = await salesforceApiRequest . call ( this , 'POST' , '/sobjects/casecomment' , body ) ;
}
}
if ( resource === 'task' ) {
//https://developer.salesforce.com/docs/api-explorer/sobject/Task/post-task
if ( operation === 'create' ) {
const additionalFields = this . getNodeParameter ( 'additionalFields' , i ) as IDataObject ;
const status = this . getNodeParameter ( 'status' , i ) as string ;
const body : ITask = {
Status : status ,
} ;
2020-08-26 23:16:50 -07:00
if ( additionalFields . whoId !== undefined ) {
2020-02-10 12:55:28 -08:00
body . WhoId = additionalFields . whoId as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . whatId !== undefined ) {
2020-02-10 12:55:28 -08:00
body . WhatId = additionalFields . whatId as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . owner !== undefined ) {
2020-02-10 12:55:28 -08:00
body . OwnerId = additionalFields . owner as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . subject !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Subject = additionalFields . subject as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . callType !== undefined ) {
2020-02-10 12:55:28 -08:00
body . CallType = additionalFields . callType as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . priority !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Priority = additionalFields . priority as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . callObject !== undefined ) {
2020-02-10 12:55:28 -08:00
body . CallObject = additionalFields . callObject as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . description !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Description = additionalFields . description as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . activityDate !== undefined ) {
2020-02-10 12:55:28 -08:00
body . ActivityDate = additionalFields . activityDate as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . isReminderSet !== undefined ) {
2020-02-10 12:55:28 -08:00
body . IsReminderSet = additionalFields . isReminderSet as boolean ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . recurrenceType !== undefined ) {
2020-02-10 12:55:28 -08:00
body . RecurrenceType = additionalFields . recurrenceType as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . callDisposition !== undefined ) {
2020-02-10 12:55:28 -08:00
body . CallDisposition = additionalFields . callDisposition as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . reminderDateTime !== undefined ) {
2020-02-10 12:55:28 -08:00
body . ReminderDateTime = additionalFields . reminderDateTime as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . recurrenceInstance !== undefined ) {
2020-02-10 12:55:28 -08:00
body . RecurrenceInstance = additionalFields . recurrenceInstance as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . recurrenceInterval !== undefined ) {
2020-02-10 12:55:28 -08:00
body . RecurrenceInterval = additionalFields . recurrenceInterval as number ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . recurrenceDayOfMonth !== undefined ) {
2020-02-10 12:55:28 -08:00
body . RecurrenceDayOfMonth = additionalFields . recurrenceDayOfMonth as number ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . callDurationInSeconds !== undefined ) {
2020-02-10 12:55:28 -08:00
body . CallDurationInSeconds = additionalFields . callDurationInSeconds as number ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . recurrenceEndDateOnly !== undefined ) {
2020-02-10 12:55:28 -08:00
body . RecurrenceEndDateOnly = additionalFields . recurrenceEndDateOnly as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . recurrenceMonthOfYear !== undefined ) {
2020-02-10 12:55:28 -08:00
body . RecurrenceMonthOfYear = additionalFields . recurrenceMonthOfYear as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . recurrenceDayOfWeekMask !== undefined ) {
2020-02-10 12:55:28 -08:00
body . RecurrenceDayOfWeekMask = additionalFields . recurrenceDayOfWeekMask as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . recurrenceStartDateOnly !== undefined ) {
2020-02-10 12:55:28 -08:00
body . RecurrenceStartDateOnly = additionalFields . recurrenceStartDateOnly as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . recurrenceTimeZoneSidKey !== undefined ) {
2020-02-10 12:55:28 -08:00
body . RecurrenceTimeZoneSidKey = additionalFields . recurrenceTimeZoneSidKey as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . recurrenceRegeneratedType !== undefined ) {
2020-02-10 12:55:28 -08:00
body . RecurrenceRegeneratedType = additionalFields . recurrenceRegeneratedType as string ;
}
responseData = await salesforceApiRequest . call ( this , 'POST' , '/sobjects/task' , body ) ;
}
//https://developer.salesforce.com/docs/api-explorer/sobject/Task/patch-task-id
if ( operation === 'update' ) {
const taskId = this . getNodeParameter ( 'taskId' , i ) as string ;
const updateFields = this . getNodeParameter ( 'updateFields' , i ) as IDataObject ;
const body : ITask = { } ;
2020-08-26 23:16:50 -07:00
if ( updateFields . whoId !== undefined ) {
2020-02-10 12:55:28 -08:00
body . WhoId = updateFields . whoId as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . status !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Status = updateFields . status as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . whatId !== undefined ) {
2020-02-10 12:55:28 -08:00
body . WhatId = updateFields . whatId as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . owner !== undefined ) {
2020-02-10 12:55:28 -08:00
body . OwnerId = updateFields . owner as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . subject !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Subject = updateFields . subject as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . callType !== undefined ) {
2020-02-10 12:55:28 -08:00
body . CallType = updateFields . callType as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . priority !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Priority = updateFields . priority as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . callObject !== undefined ) {
2020-02-10 12:55:28 -08:00
body . CallObject = updateFields . callObject as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . description !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Description = updateFields . description as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . activityDate !== undefined ) {
2020-02-10 12:55:28 -08:00
body . ActivityDate = updateFields . activityDate as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . isReminderSet !== undefined ) {
2020-02-10 12:55:28 -08:00
body . IsReminderSet = updateFields . isReminderSet as boolean ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . recurrenceType !== undefined ) {
2020-02-10 12:55:28 -08:00
body . RecurrenceType = updateFields . recurrenceType as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . callDisposition !== undefined ) {
2020-02-10 12:55:28 -08:00
body . CallDisposition = updateFields . callDisposition as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . reminderDateTime !== undefined ) {
2020-02-10 12:55:28 -08:00
body . ReminderDateTime = updateFields . reminderDateTime as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . recurrenceInstance !== undefined ) {
2020-02-10 12:55:28 -08:00
body . RecurrenceInstance = updateFields . recurrenceInstance as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . recurrenceInterval !== undefined ) {
2020-02-10 12:55:28 -08:00
body . RecurrenceInterval = updateFields . recurrenceInterval as number ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . recurrenceDayOfMonth !== undefined ) {
2020-02-10 12:55:28 -08:00
body . RecurrenceDayOfMonth = updateFields . recurrenceDayOfMonth as number ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . callDurationInSeconds !== undefined ) {
2020-02-10 12:55:28 -08:00
body . CallDurationInSeconds = updateFields . callDurationInSeconds as number ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . recurrenceEndDateOnly !== undefined ) {
2020-02-10 12:55:28 -08:00
body . RecurrenceEndDateOnly = updateFields . recurrenceEndDateOnly as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . recurrenceMonthOfYear !== undefined ) {
2020-02-10 12:55:28 -08:00
body . RecurrenceMonthOfYear = updateFields . recurrenceMonthOfYear as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . recurrenceDayOfWeekMask !== undefined ) {
2020-02-10 12:55:28 -08:00
body . RecurrenceDayOfWeekMask = updateFields . recurrenceDayOfWeekMask as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . recurrenceStartDateOnly !== undefined ) {
2020-02-10 12:55:28 -08:00
body . RecurrenceStartDateOnly = updateFields . recurrenceStartDateOnly as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . recurrenceTimeZoneSidKey !== undefined ) {
2020-02-10 12:55:28 -08:00
body . RecurrenceTimeZoneSidKey = updateFields . recurrenceTimeZoneSidKey as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . recurrenceRegeneratedType !== undefined ) {
2020-02-10 12:55:28 -08:00
body . RecurrenceRegeneratedType = updateFields . recurrenceRegeneratedType as string ;
}
responseData = await salesforceApiRequest . call ( this , 'PATCH' , ` /sobjects/task/ ${ taskId } ` , body ) ;
}
//https://developer.salesforce.com/docs/api-explorer/sobject/Task/get-task-id
if ( operation === 'get' ) {
const taskId = this . getNodeParameter ( 'taskId' , i ) as string ;
responseData = await salesforceApiRequest . call ( this , 'GET' , ` /sobjects/task/ ${ taskId } ` ) ;
}
//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 ;
2020-02-12 22:35:56 -08:00
const fields = [ 'id,subject,status,priority' ] ;
2020-02-10 12:55:28 -08:00
if ( options . fields ) {
// @ts-ignore
2020-02-12 22:35:56 -08:00
fields . push ( . . . options . fields . split ( ',' ) ) ;
2020-02-10 12:55:28 -08:00
}
try {
if ( returnAll ) {
2020-07-30 02:35:36 -07:00
qs . q = ` SELECT ${ fields . join ( ',' ) } FROM Task ` ;
2020-02-10 12:55:28 -08:00
responseData = await salesforceApiRequestAllItems . call ( this , 'records' , 'GET' , '/query' , { } , qs ) ;
} else {
const limit = this . getNodeParameter ( 'limit' , i ) as number ;
qs . q = ` SELECT ${ fields . join ( ',' ) } FROM Task Limit ${ limit } ` ;
responseData = await salesforceApiRequestAllItems . call ( this , 'records' , 'GET' , '/query' , { } , qs ) ;
}
} catch ( err ) {
throw new Error ( ` Salesforce Error: ${ err } ` ) ;
}
}
//https://developer.salesforce.com/docs/api-explorer/sobject/Task/delete-task-id
if ( operation === 'delete' ) {
const taskId = this . getNodeParameter ( 'taskId' , i ) as string ;
try {
responseData = await salesforceApiRequest . call ( this , 'DELETE' , ` /sobjects/task/ ${ taskId } ` ) ;
} catch ( err ) {
throw new Error ( ` Salesforce Error: ${ err } ` ) ;
}
}
//https://developer.salesforce.com/docs/api-explorer/sobject/Task/get-task
if ( operation === 'getSummary' ) {
responseData = await salesforceApiRequest . call ( this , 'GET' , '/sobjects/task' ) ;
}
}
if ( resource === 'attachment' ) {
//https://developer.salesforce.com/docs/api-explorer/sobject/Attachment/post-attachment
if ( operation === 'create' ) {
const name = this . getNodeParameter ( 'name' , i ) as string ;
const parentId = this . getNodeParameter ( 'parentId' , i ) as string ;
const additionalFields = this . getNodeParameter ( 'additionalFields' , i ) as IDataObject ;
const binaryPropertyName = this . getNodeParameter ( 'binaryPropertyName' , i ) as string ;
const body : IAttachment = {
Name : name ,
ParentId : parentId ,
} ;
if ( items [ i ] . binary && items [ i ] . binary ! [ binaryPropertyName ] ) {
body . Body = items [ i ] . binary ! [ binaryPropertyName ] . data ;
body . ContentType = items [ i ] . binary ! [ binaryPropertyName ] . mimeType ;
} else {
throw new Error ( ` The property ${ binaryPropertyName } does not exist ` ) ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . description !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Description = additionalFields . description as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . owner !== undefined ) {
2020-02-10 12:55:28 -08:00
body . OwnerId = additionalFields . owner as string ;
}
2020-08-26 23:16:50 -07:00
if ( additionalFields . isPrivate !== undefined ) {
2020-02-10 12:55:28 -08:00
body . IsPrivate = additionalFields . isPrivate as boolean ;
}
responseData = await salesforceApiRequest . call ( this , 'POST' , '/sobjects/attachment' , body ) ;
}
//https://developer.salesforce.com/docs/api-explorer/sobject/Attachment/patch-attachment-id
if ( operation === 'update' ) {
const attachmentId = this . getNodeParameter ( 'attachmentId' , i ) as string ;
const updateFields = this . getNodeParameter ( 'updateFields' , i ) as IDataObject ;
const body : IAttachment = { } ;
2020-08-26 23:16:50 -07:00
if ( updateFields . binaryPropertyName !== undefined ) {
2020-02-10 12:55:28 -08:00
const binaryPropertyName = updateFields . binaryPropertyName as string ;
if ( items [ i ] . binary && items [ i ] . binary ! [ binaryPropertyName ] ) {
body . Body = items [ i ] . binary ! [ binaryPropertyName ] . data ;
body . ContentType = items [ i ] . binary ! [ binaryPropertyName ] . mimeType ;
} else {
throw new Error ( ` The property ${ binaryPropertyName } does not exist ` ) ;
}
}
2020-08-26 23:16:50 -07:00
if ( updateFields . name !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Name = updateFields . name as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . description !== undefined ) {
2020-02-10 12:55:28 -08:00
body . Description = updateFields . description as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . owner !== undefined ) {
2020-02-10 12:55:28 -08:00
body . OwnerId = updateFields . owner as string ;
}
2020-08-26 23:16:50 -07:00
if ( updateFields . isPrivate !== undefined ) {
2020-02-10 12:55:28 -08:00
body . IsPrivate = updateFields . isPrivate as boolean ;
}
responseData = await salesforceApiRequest . call ( this , 'PATCH' , ` /sobjects/attachment/ ${ attachmentId } ` , body ) ;
}
//https://developer.salesforce.com/docs/api-explorer/sobject/Attachment/get-attachment-id
if ( operation === 'get' ) {
const attachmentId = this . getNodeParameter ( 'attachmentId' , i ) as string ;
responseData = await salesforceApiRequest . call ( this , 'GET' , ` /sobjects/attachment/ ${ attachmentId } ` ) ;
}
//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 ;
2020-02-12 22:35:56 -08:00
const fields = [ 'id,name' ] ;
2020-02-10 12:55:28 -08:00
if ( options . fields ) {
// @ts-ignore
2020-02-12 22:35:56 -08:00
fields . push ( . . . options . fields . split ( ',' ) ) ;
2020-02-10 12:55:28 -08:00
}
try {
if ( returnAll ) {
2020-07-30 02:35:36 -07:00
qs . q = ` SELECT ${ fields . join ( ',' ) } FROM Attachment ` ;
2020-02-10 12:55:28 -08:00
responseData = await salesforceApiRequestAllItems . call ( this , 'records' , 'GET' , '/query' , { } , qs ) ;
} else {
const limit = this . getNodeParameter ( 'limit' , i ) as number ;
qs . q = ` SELECT ${ fields . join ( ',' ) } FROM Attachment Limit ${ limit } ` ;
responseData = await salesforceApiRequestAllItems . call ( this , 'records' , 'GET' , '/query' , { } , qs ) ;
}
} catch ( err ) {
throw new Error ( ` Salesforce Error: ${ err } ` ) ;
}
}
//https://developer.salesforce.com/docs/api-explorer/sobject/Attachment/delete-attachment-id
if ( operation === 'delete' ) {
const attachmentId = this . getNodeParameter ( 'attachmentId' , i ) as string ;
try {
responseData = await salesforceApiRequest . call ( this , 'DELETE' , ` /sobjects/attachment/ ${ attachmentId } ` ) ;
} catch ( err ) {
throw new Error ( ` Salesforce Error: ${ err } ` ) ;
}
}
//https://developer.salesforce.com/docs/api-explorer/sobject/Attachment/get-attachment-id
if ( operation === 'getSummary' ) {
responseData = await salesforceApiRequest . call ( this , 'GET' , '/sobjects/attachment' ) ;
}
}
if ( Array . isArray ( responseData ) ) {
returnData . push . apply ( returnData , responseData as IDataObject [ ] ) ;
} else {
2020-02-12 22:35:56 -08:00
if ( responseData === undefined ) {
// Make sure that always valid JSON gets returned which also matches the
// Salesforce default response
responseData = {
errors : [ ] ,
success : true ,
} ;
}
2020-02-10 12:55:28 -08:00
returnData . push ( responseData as IDataObject ) ;
}
}
return [ this . helpers . returnJsonArray ( returnData ) ] ;
}
}