Source: quick-action.js

  1. /**
  2. * @file Represents Salesforce QuickAction
  3. * @author Shinichi Tomita <shinichi.tomita@gmail.com>
  4. */
  5. 'use strict';
  6. /**
  7. * A class for quick action
  8. *
  9. * @protected
  10. * @constructor
  11. */
  12. var QuickAction = module.exports = function(conn, path) {
  13. this._conn = conn;
  14. this._path = path;
  15. };
  16. /**
  17. * @typedef {Object} QuickAction~QuickActionInfo
  18. * @prop {String} type - Type of the action (e.g. Create, Update, Post, LogACall)
  19. * @prop {String} name - Name of the action
  20. * @prop {String} label - Label of the action
  21. * @prop {Object} urls - Endpoint URL information of the action
  22. */
  23. /**
  24. * @typedef {QuickAction~QuickActionInfo} QuickAction~QuickActionDescriveInfo
  25. * @prop {String} contextSobjectType - Object type used for the action
  26. * @prop {String} targetSobjectType - Object type of the action to target
  27. * @prop {String} targetParentField - Field name in the target object which refers parent(context) object record ID.
  28. * @prop {String} targetRecordTypeId - Record type of the targeted record
  29. * @prop {Object} layout - Layout sections that comprise an action
  30. */
  31. /**
  32. * Describe the action's information (including layout, etc.)
  33. *
  34. * @param {Callback.<QuickAction~QuickActionDescriveInfo>} [callback] - Callback function
  35. * @returns {Promise.<QuickAction~QuickActionDescriveInfo>}
  36. */
  37. QuickAction.prototype.describe = function(callback) {
  38. var url = this._path + "/describe";
  39. return this._conn.request(url).thenCall(callback);
  40. };
  41. /**
  42. * Retrieve default field values in the action (for given record, if specified)
  43. *
  44. * @param {String} [contextId] - ID of record to get default values specific to the record
  45. * @param {Callback.<Record>} [callback] - Callback function
  46. * @returns {Promise.<Record>}
  47. */
  48. QuickAction.prototype.defaultValues = function(contextId, callback) {
  49. if (typeof contextId === 'function') {
  50. callback = contextId;
  51. contextId = null;
  52. }
  53. var url = this._path + "/defaultValues";
  54. if (contextId) {
  55. url += "/" + contextId;
  56. }
  57. return this._conn.request(url).thenCall(callback);
  58. };
  59. /**
  60. * @typedef {Object} QuickAction~QuickActionResult
  61. * @param {String} id - Record id of the action result
  62. * @param {Array.<String>} feedItemIds - List of IDs for feed item
  63. * @param {Boolean} success - True if the action successfully completed
  64. * @param {Boolean} created - True if the action yields a new record
  65. * @param {String} contextId - Context record ID of the action
  66. * @param {Array.<Object>} errors - Errors if the action failed
  67. */
  68. /**
  69. * Execute the action for given context Id and record information
  70. *
  71. * @param {String} contextId - Context record ID of the action
  72. * @param {Record} record - Input record information for the action
  73. * @param {Callback.<QuickAction~QuickActionResult>} [callback] - Callback function
  74. * @returns {Promise.<QuickAction~QuickActionResult>}
  75. */
  76. QuickAction.prototype.execute = function(contextId, record, callback) {
  77. var body = {
  78. contextId: contextId,
  79. record: record
  80. };
  81. return this._conn.requestPost(this._path, body).thenCall(callback);
  82. };