---
schema_version: "1"
id: da1ac1cfa07beb9b76e1352daae0d6cabc9b6d8ac923e990f9f53d161d118373
title: Publisher APIs in Salesforce Classic
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform/case_feed_dev_guide/guides/quickactions/case-feed-dev-guide-component-interactions.md
canonical_url: https://developer.salesforce.com/docs/platform/case-feed-dev-guide/guide/case-feed-dev-guide-component-interactions.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: c25a0068c199e365e763374eba7190bc7701fa6b995da142c623603007030d13
products:
  - Publisher and Quick Action Developer Guide
  - Platform Developer Content
---

# Publisher APIs in Salesforce Classic

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.

|Required Editions|
|-----------------|
|Available in: Salesforce Classic ([not available in all orgs](https://help.salesforce.com/s/articleView?id=xcloud.overview_edition_lex_only.htm&type=5))|
|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.

**tip:** 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.

```html
<script src="/canvas/sdk/js/43.0/publisher.js" type="text/javascript"></script>
```

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`

|Description|Payload Values|Available Versions|
|-----------|--------------|------------------|
|Selects the specified action and puts it in focus.|`actionName`—The action to select. Supported values are:<ul><li>_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`.</li><li>`Case.CaseComment`—Case Feed portal action</li><li>`Case.ChangeStatus`—Case Feed change status action</li><li>`Case.Email`—Case Feed email action</li><li>`Case.LogACall`—Case Feed log a call action</li><li>`FeedItem.TextPost`—Standard Chatter post action (Available in API versions 32.0 and later)</li><li>_SocialPostAPIName_`.SocialPost`—Social post action (Available in API versions 32.0 and later)</li></ul>|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`

|Description|Payload Values|Available Versions|
|-----------|--------------|------------------|
|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.<ul><li>`emailFields`–Available on `Case.Email`; the standard available fields on the Case Feed email action:<ul><li>`to`</li><li>`cc`</li><li>`bcc`</li><li>`subject`</li><li>`body`</li><li>`template`</li></ul></li><li>`portalPostFields`–Available on `Case.CaseComment`; the standard available fields on the Case Feed portal action:<ul><li>`body`</li><li>`sendEmail` (boolean)</li></ul></li><li>`targetFields`–Available on `Case.ChangeStatus` , `Case.LogACall`, `FeedItem.TextPost`, and the Social action; the standard available fields on those actions.<ul><li>On `Case.ChangeStatus`: `commentBody`</li><li>On `Case.LogACall`: `description`</li><li>On `FeedItem.TextPost`: `body`<br/><br/>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)</li><li>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)</li></ul></li><li>`parentFields`—Available on `Case.ChangeStatus`, `Case.Email`, and `Case.LogACall`; standard and custom fields on case. Lookup fields aren’t supported.</li></ul>|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.

      ```javascript
      Sfdc.canvas.publisher.publish({name:"publisher.setActionInputValues",
          payload:{actionName:"Case.Email",parentFields: {Status:{value:"Closed"}},
          emailFields: {to:{value:"customer@company.com"},cc:{value:"customer2@company.com"},
          bcc:{value:"supervisor@company.com"},
      subject:{value:"Your Issue Has Been Resolved"},
          body:{value:"Thank you for working with our support department.
              We've resolved your issue and have closed this ticket, but 
              please feel free to contact us at any time if you encounter this
              problem again or need other assistance."}}}});
      ```

      This code snippet inserts the phrase “Hello World” in the body of the Post action at the current cursor position.

      ```javascript
      Sfdc.canvas.publisher.publish({name:"publisher.setActionInputValues", payload:{actionName:"FeedItem.TextPost", targetFields:{body:{value:"Hello World", insertType:"cursor"}}}});
      ```



## `publisher.invokeAction`

|Description|Payload Values|Available Versions|
|-----------|--------------|------------------|
|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:<ul><li>`Case.Email`</li><li>`Case.CaseComment`</li><li>`Case.ChangeStatus`</li><li>`Case.LogACall`</li><li>`FeedItem.TextPost` (Available in API versions 32.0 and later)</li><li>_SocialPostAPIName_`.SocialPost` (Available in API versions 32.0 and later)</li></ul>|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`

|Description|Payload Values|Available Versions|
|-----------|--------------|------------------|
|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.

![Case Feed with Knowledge console component](https://developer.salesforce.com/media/case-feed/case_feed_with_console_component.jpg)

This code sample shows an Apex class containing a custom controller used by the Visualforce page below.

```apex
public with sharing class KBController {    
   public List<FAQ__kav> articles {get; set;}       

    public KBController() {       
       articles = [select knowledgearticleid, id, title, content__c from FAQ__kav where 
      publishstatus = 'Online' and language='en_US' order by lastpublisheddate];    
   }
}
```

This code sample shows the Visualforce page that’s used as the custom console component in the use case above.

```visualforce
<apex:page sidebar="false" controller="KBController">   
   <script type='text/javascript' src='/canvas/sdk/js/publisher.js'/>   
   <style>
      .sampleTitle { background-color: #99A3AC;color:#FFFFFF;font-size:1.1em;
      font-weight: bold;padding:3px 6px 3px 6px; }  
      .sampleHeader { }  
      .sampleArticleList { min-width: 250px; padding: 8px 0 5px 0;}  
      .sampleUl { padding: 0; margin: 0; list-style: none;}  
      .sampleLi { display: block; position: relative; margin: 0;}  
      .sampleRow { min-height: 16px; padding: 4px 10px;}  
      .emailBtn { margin: 1px 1px 1px 3px; padding: 3px 8px; color: #333; 
         border: 1px solid #b5b5b5; border-bottom-color: #7f7f7f; background: #e8e8e9; 
         font-weight: bold; font-size: .9em; -moz-border-radius: 3px;
         -webkit-border-radius: 3px; order-radius: 3px; }  
      .emailBtn:active { background-position: right -60px; border-color: #585858; 
         border-bottom-color: #939393; }       
      .sampleArticle { padding-left: 4px; padding-bottom: 2px; font-weight: bold; 
         font-size: 1em; color: #222; }  
      .sampleLink { color: #015ba7; text-decoration: none; font-weight: bold; 
         font-size: .9em; }    
   </style>    
   <script>
      function emailArticle(content) {   
         Sfdc.canvas.publisher.publish({name: 'publisher.selectAction', 
         payload: { actionName: 'Case.Email'}}); 
         Sfdc.canvas.publisher.publish({name: 'publisher.setActionInputValues', 
         payload: {
            actionName: 'Case.Email',
            emailFields: { body: { value:content, format:'richtext', insert: true}}
         }});
     }
   </script>
   <div style="margin-left:-10px;margin-right:-10px;">
      <div class="sampleTitle">Latest Articles</div>
      <div class="sampleHeader" style=""></div>
      <div class="sampleArticleList">
         <apex:repeat value="{!articles}" var="article">
            <ul class="sampleUl">
               <li class="sampleLi">
                  <div class="sampleRow">
                  <div style="display:none;" id="content_{!article.id}">
                     <apex:outputText value="{!article.content__c}" escape="false"/>
                  </div>
                     <input type="button" title="Email" value="Email" class="emailBtn" 
                        onclick="emailArticle(document.getElementById
                           ('content_{!article.id}').innerHTML);"/>
                           <span class="sampleArticle">
                               <a href="/{!article.knowledgearticleid}"
                                   title="{!article.title}" class="sampleLink">
                                  {!article.title}</a>
                           </span>
                  </div>
               </li>
            </ul>
         </apex:repeat>
      </div>
   </div>
</apex:page>
```

