Batch Post IDs to Visualforce Page
Custom Action Name
Web_Post_(PostObjectName)_From_(TableName)
Objects affected
None
Description
This custom action lets you post record IDs to a Visualforce page.
Use Cases
Pass a list of IDs to a Visualforce page to use them in a process that the Visualforce page can initiate.
Steps
// Load in a CRMC library for entry window (note these are undocumented and unsupported for now)crmc.require(['sfdc', 'KendoPopup'], function (sfdc, popup) {/** * @author CRMCulture * @description Basic Salesforce POST example*//** * "ITEM_ID" Is the ID that uniquely identifies our Action item, Paste it into the action name value. * "CONTEXT_OBJECT" Is the context object that your action is based on, use API name. * "ACTION_LABEL" Is the lable that will be displayed in the context menu.*/var ITEM_ID = "Web_Post_(PostObjectName)_From_(TableName)";var CONTEXT_OBJECT = "Account";var ACTION_LABEL = "POST Hello World";/** * @DESCRIPTION: In order to get garantee a session for the user we must need to make a static resource call. Otherwise the first time a user runs this action they will get a no records selected error... the resource must be of type Javascript it's a known Salesforce bug and this is currently the most effective way to solve the issue. * "APP_PACKAGE_NAME" Is the Package Name of the application you need to create a session for. * "APP_NAMESPACE_PREFIX" Is the Prefix to the application you need to create a session for. * "APP_STATIC_RESOURCE_MINE_TYPE" Is file MINE Type of the Static Resource within the application. * "APP_STATIC_RESOURCE_NAME" Is the Name of the Static Resource being called within the application. * "APP_APEX_CLASS_NAME" Is the apex class name of your */var APP_PACKAGE_NAME = "Package Name";var APP_NAMESPACE_PREFIX = "Prefix";var APP_STATIC_RESOURCE_MINE_TYPE = "text/javascript";var APP_STATIC_RESOURCE_NAME = "Resource Name";var APP_APEX_CLASS_NAME = "Apex Class Name";/** Language strings.*/var COULD_NOT_OBTAIN_SESSION_FOR = "Could not obtain session for ";var IS_THE_APP_INSTALLED = " is the app installed?";var PLEASE_SELECT_RECORDS = "Please select records";var SELECT_AT_LEAST_ONE_RECORD_TO_POST = 'Select at least one record to post.'///////////////////////////////////////** * Custom action core code below.*/////////////////////////////////////// crmc.addCustomAction({ "itemID": "ITEM_ID", "isAvailable": function (context) { // This function is called before the action item is displayed and returns a boolean if the item should be displayed // By default determine availability based on Feature Security for this action var isEnabled = this.featureSecurity.getSetting(context.objectDescribe.name, this.itemID) !== false; // Only allow batch adding from Accounts object for now var isAccessible = context.objectDescribe.name == CONTEXT_OBJECT; var multipleSelected = context.selectedRows && context.selectedRows.length > 0; return isAccessible && isEnabled && multipleSelected; }, "getLabel": function (context) { // This function returns the display label of the action item and is called before the item is shown return "ACTION_LABEL"; }, "createSubmenuItems": function (context) { // If this function returns additional action item objects, they will appear as submenu items return []; }, "click": function (context) { //https://acctseed.cs7.visual.force.com/apex/AccountPayablePayBatch?retURL=%2Fa0H%3Ffcf%3D00BF0000006rihU%26rolodexIndex%3D-1%26page%3D1&wrapMassAction=1&scontrolCaching=1 // Include static resource from managed namespace pre-creates session and allows us to safely POST data without redirect issue var head = document.getElementsByTagName('HEAD').item(0); var script = document.createElement("script"); script.type = APP_STATIC_RESOURCE_MINE_TYPE; head.appendChild(script); var domains = window.location.hostname.split("."); if (domains.length == 3) { instance = domains[0]; } else { instance = domains[1]; } //script.src = "https://AcctSeed." + instance + ".visual.force.com/resource/AcctSeed__ButtonJSFunctions?ts=" + new Date().getTime(); script.src = "https://" + APP_NAMESPACE_PREFIX + "." + instance + ".visual.force.com/resource/" + APP_NAMESPACE_PREFIX + "__" + APP_STATIC_RESOURCE_NAME + "?ts=" + new Date().getTime(); script.onerror = function() { // Couldn't load app script, assume not installed popup.popup(COULD_NOT_OBTAIN_SESSION_FOR + APP_PACKAGE_NAME + IS_THE_APP_INSTALLED); }; //POST script.onload = function() { //If any rows are selected. POST with the given id's. if (context.selectedRows.length > 0) { var selectedIds = []; Object.each(context.selectedRows, function (item) { selectedIds.push({name: "ids", value: item["Id"]}); }); var parameters = { retURL: context.actionGrid.settings.pageURL, }; sfdc.postToVFPage(APP_NAMESPACE_PREFIX, APP_APEX_CLASS_NAME, parameters, selectedIds); } else { popup.popup(PLEASE_SELECT_RECORDS, SELECT_AT_LEAST_ONE_RECORD_TO_POST); } }; } });});