Source: api/soap.js

  1. /**
  2. * @file Salesforce SOAP API
  3. * @author Shinichi Tomita <shinichi.tomita@gmail.com>
  4. */
  5. 'use strict';
  6. var _ = require('lodash/core');
  7. var jsforce = require('../core');
  8. var SOAP = require('../soap');
  9. /**
  10. * API class for Partner SOAP call
  11. *
  12. * @class
  13. * @param {Connection} conn - Connection
  14. */
  15. var SoapApi = module.exports = function(conn) {
  16. this._conn = conn;
  17. };
  18. /**
  19. * Call SOAP Api (Partner) endpoint
  20. * @private
  21. */
  22. SoapApi.prototype._invoke = function(method, message, schema, callback) {
  23. var soapEndpoint = new SOAP(this._conn, {
  24. xmlns: "urn:partner.soap.sforce.com",
  25. endpointUrl: this._conn.instanceUrl + "/services/Soap/u/" + this._conn.version
  26. });
  27. return soapEndpoint.invoke(method, message, { result: schema }).then(function(res) {
  28. return res.result;
  29. }).thenCall(callback);
  30. };
  31. /* */
  32. var Schemas = {};
  33. /**
  34. * @typedef SoapApi~LeadConvert
  35. * @prop {String} convertedStatus - Status of converted lead
  36. * @prop {String} leadId - Lead record Id to convert
  37. * @prop {String} [accountId] - Account record Id to assign the converted record
  38. * @prop {String} [contactId] - Contact record Id to assign the converted record
  39. * @prop {Boolean} [doNotCreateOpportunity] - True if you don't want to create a new opportunity
  40. * @prop {String} [opportunityName] - Name of opportunity to create
  41. * @prop {Boolean} [overwriteLeadSource] - True if overwriting lead source
  42. * @prop {String} [ownerId] - Owner Id
  43. * @prop {Boolean} [sendNotificationEmail] - True if send notification email
  44. */
  45. /**
  46. * @typedef SoapApi~LeadConvertResult
  47. * @prop {String} leadId - Lead record Id to convert
  48. * @prop {String} [accountId] - Account record Id of converted lead
  49. * @prop {String} [contactId] - Contact record Id of converted lead
  50. * @prop {String} [opportunityId] - Opportunity record Id created in conversion
  51. * @prop {Boolean} success - True if successfully converted
  52. * @prop {Array.<Object>} errors - Error
  53. */
  54. /**
  55. * Converts a Lead into an Account, Contact, or (optionally) an Opportunity.
  56. *
  57. * @param {SoapApi~LeadConvert|Array.<SoapApi~LeadConvert>} leadConverts
  58. * @param {Callback.<SoapApi~LeadConvertResult|Array.<SoapApi~LeadConvertResult>>} [callback] - Callback function
  59. * @returns {Promise.<SoapApi~LeadConvertResult|Array.<SoapApi~LeadConvertResult>>}
  60. */
  61. SoapApi.prototype.convertLead = function(leadConverts, callback) {
  62. var schema = _.isArray(leadConverts) ? [ Schemas.LeadConvertResult ] : Schemas.LeadConvertResult;
  63. return this._invoke("convertLead", { leadConverts: leadConverts }, schema, callback);
  64. };
  65. Schemas.LeadConvertResult = {
  66. success: 'boolean',
  67. errors: [],
  68. leadId: 'string',
  69. accountId: 'string',
  70. contactId: 'string',
  71. opportunityId: 'string'
  72. };
  73. /**
  74. * @typedef SoapApi~MergeRequest
  75. * @prop {Object} masterRecord - The merge destination record
  76. * @prop {Array.<String>} recordToMergeIds - Ids of records to merge
  77. */
  78. /**
  79. * @typedef SoapApi~MergeResult
  80. * @prop {Boolean} success - True if successfully merged
  81. * @prop {Array.<Object>} errors - Error
  82. * @prop {String} id - ID of the master record
  83. * @prop {Array.<String>} mergedRecordIds - ID of the records that were merged into the master record
  84. * @prop {Array.<String>} updatedRelatedIds - ID of all related records that were moved (re-parented) as a result of the merge
  85. */
  86. /**
  87. * Merge up to three records into one
  88. *
  89. * @param {SoapApi~MergeRequest|Array.<SoapApi~MergeRequest>} mergeRequests
  90. * @param {Callback.<SoapApi~MergeResult|Array.<SoapApi~MergeResult>>} [callback] - Callback function
  91. * @returns {Promise.<SoapApi~MergeResult|Array.<SoapApi~MergeResult>>}
  92. */
  93. SoapApi.prototype.merge = function(mergeRequests, callback) {
  94. var schema = _.isArray(mergeRequests) ? [ Schemas.MergeResult ] : Schemas.MergeResult;
  95. return this._invoke("merge", { mergeRequests: mergeRequests }, schema, callback);
  96. };
  97. Schemas.MergeResult = {
  98. success: 'boolean',
  99. errors: [],
  100. id: 'string',
  101. mergedRecordIds: ['string'],
  102. updatedRelatedIds: ['string']
  103. };
  104. /**
  105. * @typedef SoapApi~EmptyRecycleBinResult
  106. * @prop {String} id - ID of an sObject that you attempted to delete from the Recycle Bin
  107. * @prop {Boolean} success - Whether the call succeeded (true) or not (false) for this record
  108. * @prop {Array.<Object>} errors - Errors
  109. */
  110. /**
  111. * Delete records from the recycle bin immediately
  112. *
  113. * @param {Array.<String>} ids - Record ids to empty from recycle bin
  114. * @param {Callback.<Array.<SoapApi~EmptyRecycleBinResult>>} [callback] - Callback function
  115. * @returns {Promise.<Array.<SoapApi~EmptyRecycleBinResult>>}
  116. */
  117. SoapApi.prototype.emptyRecycleBin = function(ids, callback) {
  118. return this._invoke("emptyRecycleBin", { ids: ids }, [ Schemas.EmptyRecycleBinResult ], callback);
  119. };
  120. Schemas.EmptyRecycleBinResult = {
  121. id: 'string',
  122. success: 'boolean',
  123. errors: []
  124. };
  125. /**
  126. * @typedef SoapApi~DescribeTabSetResult
  127. * @prop {String} label - The display label for this standard or custom app
  128. * @prop {String} logoUrl - A fully qualified URL to the logo image associated with the standard or custom app
  129. * @prop {String} namespace - Namespace of application package
  130. * @prop {Boolean} selected - If true, then this standard or custom app is the user’s currently selected app
  131. * @prop {Array.<SoapApi~DescribeTab>} tabs - An array of tabs that are displayed for the specified standard app or custom app
  132. */
  133. /**
  134. * @typedef SoapApi~DescribeTab
  135. * @prop {Array.<Object>} colors - Array of color information used for a tab
  136. * @prop {Boolean} custom - true if this is a custom tab
  137. * @prop {String} iconUrl - The URL for the main 32 x 32 pixel icon for a tab
  138. * @prop {Array.<Object>} icons - Array of icon information used for a tab
  139. * @prop {String} label - The display label for this tab
  140. * @prop {String} miniIconUrl - The URL for the 16 x 16 pixel icon that represents a tab
  141. * @prop {String} name - The API name of the tab
  142. * @prop {String} sobjectName - The name of the sObject that is primarily displayed on this tab
  143. * @prop {String} url - A fully qualified URL for viewing this tab
  144. */
  145. /**
  146. * Returns information about the standard and custom apps available to the logged-in user
  147. *
  148. * @param {Callback.<Array.<SoapApi~DescribeTabSetResult>>} [callback] - Callback function
  149. * @returns {Promise.<Array.<SoapApi~DescribeTabSetResult>>}
  150. */
  151. SoapApi.prototype.describeTabs = function(callback) {
  152. return this._invoke("describeTabs", {}, [ Schemas.DescribeTabSetResult ], callback);
  153. };
  154. Schemas.DescribeTabSetResult = {
  155. label: 'string',
  156. logoUrl: 'string',
  157. namespace: 'string',
  158. selected: 'boolean',
  159. tabs: [{
  160. colors: [{
  161. theme: 'string',
  162. color: 'string',
  163. context: 'string'
  164. }],
  165. iconUrl: 'string',
  166. icons: [{
  167. theme: 'string',
  168. height: 'number',
  169. width: 'number',
  170. url: 'string',
  171. contentType: 'string'
  172. }],
  173. label: 'string',
  174. custom: 'boolean',
  175. miniIconUrl: 'string',
  176. name: 'string',
  177. sobjectName: 'string',
  178. url: 'string'
  179. }]
  180. };
  181. /**
  182. * Retrieves the current system timestamp (Coordinated Universal Time (UTC) time zone) from the API
  183. *
  184. * @typedef SoapApi~ServerTimestampResult
  185. * @prop {String} timestamp - Timestamp
  186. */
  187. /**
  188. * @param {Callback.<SoapApi~ServerTimestampResult>} [callback] - Callback function
  189. * @returns {Promise.<SoapApi~ServerTimestampResult>}
  190. */
  191. SoapApi.prototype.getServerTimestamp = function(callback) {
  192. return this._invoke("getServerTimestamp", {}, Schemas.GetServerTimestampResult, callback);
  193. };
  194. Schemas.GetServerTimestampResult = {
  195. timestamp: 'string'
  196. };
  197. /**
  198. * @typedef SoapApi~UserInfoResult
  199. * @prop {Boolean} accessibilityMode
  200. * @prop {String} currencySymbol
  201. * @prop {Number} orgAttachmentFileSizeLimit
  202. * @prop {String} orgDefaultCurrencyIsoCode
  203. * @prop {String} orgDisallowHtmlAttachments
  204. * @prop {Boolean} orgHasPersonAccounts
  205. * @prop {String} organizationId
  206. * @prop {Boolean} organizationMultiCurrency
  207. * @prop {String} organizationName
  208. * @prop {String} profileId
  209. * @prop {String} roleId
  210. * @prop {Number} sessionSecondsValid
  211. * @prop {String} userDefaultCurrencyIsoCode
  212. * @prop {String} userEmail
  213. * @prop {String} userFullName
  214. * @prop {String} userId
  215. * @prop {String} userLanguage
  216. * @prop {String} userLocale
  217. * @prop {String} userName
  218. * @prop {String} userTimeZone
  219. * @prop {String} userType
  220. * @prop {String} userUiSkin
  221. */
  222. /**
  223. * Retrieves personal information for the user associated with the current session
  224. *
  225. * @param {Callback.<SoapApi~UserInfoResult>} [callback] - Callback function
  226. * @returns {Promise.<SoapApi~UserInfoResult>}
  227. */
  228. SoapApi.prototype.getUserInfo = function(callback) {
  229. return this._invoke("getUserInfo", {}, Schemas.GetUserInfoResult, callback);
  230. };
  231. Schemas.GetUserInfoResult = {
  232. accessibilityMode: 'boolean',
  233. currencySymbol: 'string',
  234. orgAttachmentFileSizeLimit: 'number',
  235. orgDefaultCurrencyIsoCode: 'string',
  236. orgDisallowHtmlAttachments: 'boolean',
  237. orgHasPersonAccounts: 'boolean',
  238. organizationId: 'string',
  239. organizationMultiCurrency: 'boolean',
  240. organizationName: 'string',
  241. profileId: 'string',
  242. roleId: 'string',
  243. sessionSecondsValid: 'number',
  244. userDefaultCurrencyIsoCode: 'string',
  245. userEmail: 'string',
  246. userFullName: 'string',
  247. userId: 'string',
  248. userLanguage: 'string',
  249. userLocale: 'string',
  250. userName: 'string',
  251. userTimeZone: 'string',
  252. userType: 'string',
  253. userUiSkin: 'string'
  254. };
  255. /**
  256. * Sets the specified user’s password to the specified value
  257. *
  258. * @param {String} userId - User Id to set password
  259. * @param {String} password - New password
  260. * @param {Callback.<String>} [callback] - Callback function
  261. * @returns {Promise.<String>}
  262. */
  263. SoapApi.prototype.setPassword = function(userId, password, callback) {
  264. return this._invoke("setPassword", { userId: userId, password: password }, callback);
  265. };
  266. /**
  267. * @typedef SoapApi~ResetPasswordResult
  268. * @prop {String} password
  269. */
  270. /**
  271. * Resets the specified user’s password
  272. *
  273. * @param {String} userId - User Id to set password
  274. * @param {String} password - New password
  275. * @param {Callback.<SoapApi~ResetPasswordResult>} [callback] - Callback function
  276. * @returns {Promise.<SoapApi~ResetPasswordResult>}
  277. */
  278. SoapApi.prototype.resetPassword = function(userId, callback) {
  279. return this._invoke("resetPassword", { userId: userId }, callback);
  280. };
  281. /*--------------------------------------------*/
  282. /*
  283. * Register hook in connection instantiation for dynamically adding this API module features
  284. */
  285. jsforce.on('connection:new', function(conn) {
  286. conn.soap = new SoapApi(conn);
  287. });
  288. module.exports = SoapApi;