Salesforce Macros
A Quick Guide to Enablement and Implementation
Preamble
I normally blog about Delphi, however this is an exception. I was recently asked to examine Salesforce macros and discovered a world of difficulty in getting my arms around the conceptual framework and obscure documentation. In order to preserve and share that hard-won experience, I decided to prepare this blog. Any errors are mine and please feel free to share corrections and improvements in the comments.
Overview
As with any macro, Salesforce macros encapsulate a series of operations so that when the macro is invoked, the operations specified take place more or less automatically, thus resulting in fewer errors and greater efficiency. Salesforce is notorious for some of the worst documentation on the planet; it is generally 100% accurate and in many cases, nearly 100% useless for learning and solving problems. Macros are no exception, and the Salesforce documentation may actually be 110% useless. This guide will attempt to anticipate those deficiencies and offer the reader a quick way to navigate the false starts and poorly documented settings needed to actually get Salesforce macros to work.
This guide was developed used a Salesforce Developer Sandbox in December, 2016. The Sandbox was created sometime in November, 2016. Salesforce is a moving target, constantly rearranging, redefining and often making seemingly arbitrary changes to nomenclature and the interface. If you’re reading this a year or so after I post it, don’t be afraid to “reinterpret” my approaches and explanations to fit the current Salesforce paradigms, interfaces and idiosyncrasies.
Development Technique
Your workflow when developing macros is likely to alternate frequently between a Setup page and your running console app. Don’t hesitate to switch back and forth a lot. Work on something in the Setup and then immediately try it in your app. To minimize the keystrokes it takes to switch back and forth, note the following:
If you are displaying a console, click the gear in the upper right corner of the window to switch immediately to the Setup display.
From a non-console view, click the Setup item next to your name.
Use the Quick Find / Search box at the top of the Setup menu tree. It makes finding some setup items much faster than trying to open the reveal triangles to navigate.
When you are displaying a non-console page, a quick navigation is provided at the top of the page, on the left side of the window. This will typically say something like “Back to xyz-app.” You’re one click away from your app using this navigation aid.
Prerequisites
It is assumed that the reader knows how to find the Setup button and further that the reader has full administrative authority. You may want to work in a sandbox or developer edition but for even a beginning administrator, you probably won’t be able to do much harm to your organization if you are the least bit careful. Hence you can dive right in on your organization’s production system with some degree of confidence. Even if your macros are a dismal failure, you won’t preclude the organization’s functioning.
Macros are only available in: Professional, Enterprise, Performance, Unlimited, and Developer editions.
Click Setup➔Administer to display the edition at the top of the page. Click Setup➔Company Profile➔Company Information to display lots of useful stuff about your organization. Of particular interest are the licenses assigned to the particular instance of Salesforce you are using.
Macros are supported only on the Accounts, Cases, Contacts, and Leads objects. (Salesforce objects are nothing more than a relational entity to use standard E/R jargon.)
Macros are only available on console applications. The documentation says only on “Service Console” but that is misleading. At one time, there may have been a Service Console, but now you can designate any app to be a console app. This simply means that the user will have access to multiple records in tabs rather than the nearly unusable standard presentation Salesforce uses.
Feed Tracking must be enabled for objects (remember, only four are supported—see above) you intend to target a macro to.
Go to Setup➔Feed Tracking. Click on the object needed (remember, only four are supported for macros) and then click the Enable Feed Tracking check box at the top of the display. Remember to click Save to save the setting.
Use a feed-based page layout for objects that are targets for your macros. (Remember, only four objects are supported for macros.) This one is tougher. You must either use a feed-based layout or if none exists, create one.
Click Setup➔Customize➔the desired object, i.e. CASES➔Page Layouts. This will display all page layouts for that object. At the far right is a check-box that says "Feed-based Layout." You cannot change this setting, it is read-only. If you need to create a feed-based layout, click the New button. You will be given a chance to clone an existing layout under a new name. Be sure to check the “Feed-Based Layout” check box for your new layout! Cloning is probably the easiest way to get a feed-based layout but if you’re really ambitious, you can create your own from scratch.
After you clone or create your page layout, press the Save button to save it. You will be redirected back to the list of Page Layouts for the object you’re working on.
Click Page Layout Assignment. Click Edit Assignment. Make sure your new page is assigned to the user profiles for users who will be using macros. At the very least, if you have an Administrator profile, make sure you assign the Page Layout to System Administrator.
Go to Setup➔Apps. You can either edit an existing console app or create a new one. You cannot change a non-console app to a console app or vice versa. If you create a new app be sure to check the “Console” radio button on the first step. After the Label, Name and Description on the second step, the app logo on the third step, you arrive at the fourth step, selecting the tabs to appear. Choose the tabs you want your app to display. Remember that only Accounts, Cases, Contacts and Leads support macros so you’ll want to include at least one of those. Move on to step 5 and organize your app’s tabs. Remember that this screen controls the way records are displayed when selected outside of primary tabs or subtabs. Move to step six and choose the profiles for which your app will be visible. If you’re the Administrator, don’t forget to check “System Administrator.” Click Finish and your app is created, but it still won’t display macros. You’ll be on the App list screen. Click the Edit action for your new app. You can now make lots of changes to your console app, but the important ones are Choose List Placement: Pinned to Left is popular with about a 30% width. But choose whatever arrangement you think is best. Choose Console Components is critical. Move “Macro Browser” to the Selected Items list box to enable the Macro Browser for the app. Be sure to click Save to save all of your changes.
Writing Macros
This is the exciting part where you actually get to write and run Salesforce Macros.
Now run your app. The Macros widget should appear in the extreme lower right corner of the browser window. If it doesn’t you probably have forgotten to add the Macro Browser to the app. Go back and fix that. From the list dropdown (on the left if you followed the previous app configuration suggestion) choose Cases. Then click on a Case from the list. (This assumes you have some.) The primary and subtabs (on the right if you followed the previous app configuration suggestion) will populate with the appropriate records for the selected Case. Click on a subtab to display that record. To change views between Detail and Feed, use the icons on the right near the top of the record’s display. Now you can write a macro.
Click on the Macro Browser widget in the far lower right corner of the Salesforce browser window. The widget opens. Click on + Create Macro at the very bottom left of the widget. A new primary tab opens to edit your new macro. Fill in the name and description, then click + Add Instruction. The currently available instruction selector appears. The very first thing you’ll want to do is select the appropriate record tab. If your macro updates a Case, you’ll want to choose Select Active Case Tab, etc. Click Done to move to the next instruction. Next, choose the action you’d like to perform, for example, Update Case Action. Click Done once more. Continue in the manner until you have entered all of your instructions.
To run your macro first select the tab or subtab of a record type the macro targets. I.e, if your macro targets a Case record, select a Case record tab. Now click the Macros widget and then click on the name of the macro you’d like to run. Finally, click the run triangle that appears in the macro text box. You’ll get either a success message or error messages that will help you debug your macro.
More Prerequisites
Unfortunately, you may finally get around to writing a macro only to discover that you still lack some of the required resources. The two common deficiencies are Publisher Resources and Email. An explanation of these items follows.
Next come publisher actions. These are even more obtuse and the source of much confusion. The documentation says that publisher actions that you want to use in macros must be available on the page layout, a pretty ambiguous statement. If you are attempting to write a macro and a needed publisher action is not available in the macro editor instruction dropdown, you should check the page layout. When you are writing or editing a macro, available actions are displayed in the instruction editor dropdown list, so there is no ambiguity about an action; you either have it available or you don’t.
Go back and click Edit for the page-layout you’re using for your object. Click Quick Actions in the source pallet. This will provide a list of quick actions available to include in the section of the layout entitled “Quick Actions in the Salesforce Classic Publisher.” You may be able to simply drag the desired quick action down to the Quick Actions section and that will add the action to the macro’s dropdown list. An example of this is the “Log a Call” quick action. However, there are two instances of this quick action in the source pallet. If you hover each, you’ll discover that only one has the attribute “Create Feed Item: Yes.” This is the one to choose. The other will not appear in the macro editor.
If there are no Quick Actions available to solve your problem, you need to define your own action. After you define a new Quick Action, it will appear in the Page Layout pallet and you can drag it to the Quick Actions section of the layout. See the next bullet point for a discussion on creating quick action items.
Send an Email can be especially gnarly. This is handled in the second bullet point following. Be sure to read it if you intend to use macros to send email.
If you edit your page layout, but sure to click Save before leaving the page.
Go to Setup➔Customize➔the desired object, i.e. CASES➔Buttons, Links and Actions. Click New Action. For this example, choose Update a Record as the Action Type. Choose Change Status for the Standard Label Type. Enter Case_Status_Close for the Name. (Note the use of the snake-case underscore. This is an API name.) Enter “Close the target Case.” In the Description. Finally, enter “Case successfully modified.” In the Success Message. Finally click Save and again on the layout for the Quick Action that appears.
You will now be presented with the Action Detail page. At the top you will see the information entered when you created the Action. The next section is Predefined Field Values. Click New. On the next screen in the Field Name dropdown, choose Status. This will display a second dropdown with allowable specific values. Chose “Closed.” Click Save.
You have now created an Action that Close a case. Remember, that closing a case involves simply changing its status to “Closed,” which is what this Action does.
Go to the Page Layout you are using for the object. Click Quick Actions in the Pallet. Drag the Change Status item from the pallet to the Quick Actions section of the layout. If you have more than one Change Status item, hover over the items and choose the item that displays “Name: Case.Case_Status_Close.” This matches the name you gave the Action Item when you defined it. Click Save.
Now switch to your console app and click Macros and create a new macro. Your new action will appear in the instruction dropdown list (after first selecting the target record.) Create a macro that has the following: 1) Select Active Case Tab; 2) Select Change Status Action (this matches the name of the action); 3) Submit Action. Name and save the macro.
Test your macro on an appropriate record. This macro will change the status of a Case to Closed. (Note that this is a trivial example, as there is a Close button on the Case listing in the console. However, in complex macros, you may want to update several fields in the Case record. This can be accomplished by adding additional predefined field values in the Action item. You might also want to send email to the contact for the Case. You can include more than one action in a macro.
We arrive, finally, at sending email. This involves even more mystifying settings, especially if you’re working in a fresh Sandbox. Here’s how to make Email (actually “Select Email Action”) appear in the macro instruction dropdown list.
Go to Setup➔Email Administration➔Deliverability and make sure that “Access level” is set to “All email.” In a fresh sandbox, this may not be the value. Click Save.
Go to Setup➔Customize➔Cases➔Email to Case and make sure that “Enable Email-to-Case is checked. Click Save.
Go to Setup➔Customize➔Cases➔Page Layouts. Check to be sure Send Email appears in the Quick Actions section of the page layout you are using. If it is not, drag it in from the Quick Actions section of the pallet.
The item “Select Email Action” should now appear in your macro instruction dropdown. After you include the Email Quick Action item the next level of instructions will permit you to modify one or more message attributes, such as template, addressees, subject and so forth. Finish up with Submit Action to send your email.
You may now include other quick actions in your macro, such as closing the case. Macro design can be as simple or complex as you choose and limited only by your needs, resources and imagination.
Conclusion
Using Salesforce macros is unfortunately excessively complex and frustrating. I recommend using an iterative approach, first establishing all of the known prerequisites and then, when you have a console app running, trying to actually write a macro. When you discover a deficiency, back up and resolve the deficiency by adjusting the Page Layout, creating an Action Item, Enabling Email or some combination of all three. Try your macro again and repeat the process until you have all deficiencies resolved and your macro functions as desired.
I have obviously left out some significant parts of the administrative burden associated with macros. For example, I haven’t dwelled at all on user permissions, but take note that there are three:
Create Macros
Run Macros
Run Irreversible Macros
I leave these and other details to you, assuming you are a competent administrator and capable of addressing these issues.