The Salesforce Classic Publisher JavaScript API lets your Visualforce pages and
components interact with actions you’ve added to a record page in a Salesforce Classic app for
objects that are feed-enabled. The Publisher API works in Salesforce Classic apps with
standard navigation and console navigation. For example, you could develop a component that
generates customized, pre-written text, adds that text to a new post in the Case Feed portal
action, and submits the post to the portal, all with one click.
| Available in: Salesforce Classic (not available in all
orgs) |
| Available in: Enterprise, Performance, Unlimited, and
Developer Editions |
Use the publish method on the Sfdc.canvas.publisher object to allow console
components to interact with quick actions.
Starting with API version 43.0 of the Salesforce Classic JavaScript
Publisher API, the methods used in Visualforce components work in Lightning Experience.
You can use Visualforce pages in Lightning Experience through custom quick actions, or
by adding it to the page in the Lightning App Builder. Just point to the 43.0 version of
the Publisher API script in your Visualforce
pages.
If
you use the JavaScript Publisher API methods in custom code in a Lightning app, the
targeted quick actions must be visible on the page. If you target an action that
isn’t visible on the page, it fails.
publisher.selectAction
| Selects the specified action and
puts it in focus. |
actionName—The action to select. Supported values are:
-
action_name–A create, log a call, or custom
Visualforce quick action. For example, action_name
for a create contact action might be create_contact.
-
Case.CaseComment—Case
Feed portal action
-
Case.ChangeStatus—Case Feed change status action
-
Case.Email—Case Feed
email action
-
Case.LogACall—Case
Feed log a call action
-
FeedItem.TextPost—Standard Chatter post action
(Available in API versions 32.0 and later)
-
SocialPostAPIName.SocialPost—Social
post action (Available in API versions 32.0 and later)
|
Available in API versions 29.0 and
later. |
- Code Sample
-
This code snippet selects the email action and puts it in focus.
Sfdc.canvas.publisher.publish({name:"publisher.selectAction",payload:{actionName:"Case.Email"}});
publisher.setActionInputValues
| Specifies which fields
on the action should be populated with specific values, and what those
values are. |
actionName—The action on which fields should be populated.The available
field values depend on which action you specify.
-
emailFields–Available on Case.Email; the standard
available fields on the Case Feed email action:
- to
- cc
- bcc
- subject
- body
- template
-
portalPostFields–Available on Case.CaseComment; the standard
available fields on the Case Feed portal action:
-
targetFields–Available on Case.ChangeStatus , Case.LogACall, FeedItem.TextPost, and the
Social action; the standard available fields on those actions.
- On Case.ChangeStatus: commentBody
- On Case.LogACall:
description
- On FeedItem.TextPost: body
Attributes on
body are
value and
insertType
(optional). Valid values for insertType are begin, end, cursor, and replace. The default
value is replace.
(Available in API versions 32.0 and later)
- On SocialPostAPIName.SocialPost:
content and
insertType
(optional). Valid values for insertType are begin, end, cursor, and replace . The default value is replace. (Available in
API versions 32.0 and later)
-
parentFields—Available on Case.ChangeStatus, Case.Email, and Case.LogACall; standard and
custom fields on case. Lookup fields aren’t supported.
|
Available in API versions 29.0 and
later. |
- Code Sample
-
This code snippet populates the fields on an email message with predefined
values, and sets the status of the associated case to Closed.
This code snippet inserts the phrase “Hello World” in the body of the Post
action at the current cursor position.
publisher.invokeAction
| Triggers the submit function (such as sending
an email or posting a portal comment) on the specified
action. |
actionName—The action on which to trigger the submit function. Supported
actions are:
- Case.Email
- Case.CaseComment
- Case.ChangeStatus
- Case.LogACall
-
FeedItem.TextPost (Available
in API versions 32.0 and later)
-
SocialPostAPIName.SocialPost
(Available in API versions 32.0 and later)
|
Available in API versions 29.0 and
later. |
- Code Sample
-
This code snippet triggers the submit function on the email action, sending an
email message and generating a related feed item.
Sfdc.canvas.publisher.publish({name:"publisher.invokeAction",
payload:{actionName:"Case.Email"}});
publisher.customActionMessage
| Passes a custom event to a custom
action. Supported for Visualforce-based custom actions only. |
actionName—The Visualforce custom action to pass the event to. message–The event to pass to
the custom action.
|
Available in API versions 29.0 and
later. |
- Code Sample
-
This code snippet passes the Hello world event to the action
my_custom_action.
Sfdc.canvas.publisher.publish({name:"publisher.customActionMessage",
payload:{actionName:"my_custom_action", message:"Hello
world"}});This code snippet is what my_custom_action uses to listen
to the Hello world event.
Sfdc.canvas.publisher.subscribe([{name :
"publisher.customActionMessage", onData : function(e)
{alert(e.message);}}]);
publisher.refresh
Refreshes the current record page. This method has no arguments.
Use Case and Sample Code
Example
Universal Cable serves millions of phone and cable customers throughout the United
States, with 4000 support agents in call centers of varying sizes around the country.
Universal wanted to make it easy for agents to access the company’s extensive
collection of articles in Salesforce Knowledge and share them with customers through
email to help keep support costs in check.
Universal used the events on
publish to create
a custom console component that:
- Displays a list of Knowledge articles, from most recently published to
oldest.
- Lets agents view an article by clicking its title.
- Lets agents add the full, formatted text of an article to a message in the Case
Feed email action by clicking the Email button in the
console component.
This code sample shows an Apex class containing a custom controller used by the
Visualforce page below.
This code sample shows the Visualforce page that’s used as the custom console component
in the use case above.