When Salesforce is life!

Tag: Chatter

[Salesforce] The Sobject Crusade:AssetFeed

Source: AssetFeed

This object enables feed tracking on the Asset object.

For more details about objects’ Feed, go to AccountFeed object.

Enable feed tracking on Setup > Chatter > Feed Tracking:

And this is an Asset with feed tracking enabled:

Here is a simple query:

SELECT id, Type, Title, Body, Visibility, likecount, NetworkScope, (Select Id, FieldName, NewValue From FeedTrackedChanges) from AssetFeed

[Salesforce] The Sobject Crusade: Article Type__Feed

Source: Article Type__Feed

The object is part of the Salesforce Knowledge feature.

This feature allow CRM users to create articles or search for articles to solve customer’s cases.

To enable Knwoledge base have a look at the Article Type__DataCategorySelection object description.

To enable feed on an article, go to Setup > Customize > Chatter > Feed Tracking and select your articole type (e.g. European Offer) and click the Enable Feed Tracking checkbox:

For more details about objects’ Feed, go to AccountFeed object.

Here is what you see when enabling feed tracking on the custom article type:

Here is a simple query:

SELECT id, Type, Title, Body, Visibility, likecount, NetworkScope, (Select Id, FieldName, NewValue From FeedTrackedChanges) from European_Offer__Feed 

[Salesforce] The Sobject Crusade: Announcement

Source: Announcement

This object represents a Chatter Group Announcement.

To create a new announcement, go to the Chatter tab, select (or create) a group:

Click on More > Announcement and select the body of the announcement and an expiration date:

A section will compare on the Group’s sidebar:

The Announcement object is a detail of the FeedItem object that specifies the Expiration Date of the feed. Given the following query:

select FeedItem.Body, ExpirationDate, Parent.Name from Announcement

To create the object programmatically follow these rules:

//query the Collaboration Grouop
CollaborationGroup group = [Select Id From CollaborationGroup Where Name = 'Awesome Group'];

//creates a feed item; type "AdvancedTextPost" is mandatory
FeedItem item = new FeedItem(Type='AdvancedTextPost', ParentId=group.Id, Body='This is an awesome announcement');
insert item;

//create the announcement
Announcement anc = new announcement(FeedItemId=item.Id, ExpirationDate=System.today().addDays(10));
insert anc;

//upate the group
group.AnnouncementId=anc.Id
update group;

[Salesforce] The Sobject Crusade: ActionLinkTemplate

Back to the Sobject Crusade list.

Source: ActionLinkTemplate

Action Links has been presented when discussing the ActionLinkGroupTemplate object (see this object for a complete guide on configuring and using Action Links): they are a way to execute custom actions on button click on Chatter feed posts.

By templating an Action Link you define a template action which can be “instantiated”.

The Action Link is defined by:

  • LinkType: this is the kind of action that you want to expose, and it can be:
    • Api: direct call to an API endpoint (with given method, parameters, headsrs)
    • Api Async: like the previous point but the server response is asyncrhonous: this way the serve have to send a response to /connect/action-links/[actionLinkId] endpoint to set the SuccessfulStatus o FailedStatus of the operation
    • Download: triggers a download of a file
    • Ui: redirects to the given URL
  • ActionUrl: endpoint of the action. This could have bindings values, e.g. “https://myapi.com/id={!Bindings.customValue}&userId={!userId}”
  • Headers: headers request values (only for Api and ApiAsync), binding supported. Every header value should be in the form (one per line) “Header-key: value”
  • Method: HTTP method for the request, with the following supported behavior:
    • HttpDelete: HTTP 204 on success, response body is empty
    • HttpGet: HTTP 200 on success
    • HttpHead: HTTP 200 on success, response body is empty
    • HttpPatch: HTTP 200 on success or HTTP 204 if response body is empty
    • HttpPost: HTTP 201 on success or HTTP 204 if response body is empty
    • HttpPut: HTTP 200 on success or HTTP 204 if response body is empty

    “Ui” and “Download” types support only “HttpGet” value.

  • RequestBody: bpdy of the request (only for Api and ApiAsync), binding supported
  • LabelKey: standard set of labels (None if none apply, then use the Label field)
  • Label: custom label associated to the action (Pending, Success and Failed applied to the action action)
  • Position: position of the action in the defined group (0 is the first)
  • IsConfirmationRequired: users is prompted with a confirmation alert box upon click on the action
  • IsGroupDefault: default group action
  • UserVisibility: states who can see the action, that is Creator, Everyone, EveryoneButCreator, Manager (manager of the creator on the Action Link), CustomUser or CustomExcludedUser (using the UserAlias field to link to a specific user)
  • UserAlias: user alias to set the visibility of the action. Supports binding
  • LinkType:
  • LinkType:

You can query this object:

Select Id, ActionLinkGroupTemplate.DeveloperName, LinkType, ActionUrl, Headers, IsConfirmationRequired, Label, Method, RequestBody From ActionLinkTemplate

And get:

[Salesforce] The Sobject Crusade: ActionLinkGroupTemplate

Back to the Sobject Crusade list.

Source: ActionLinkGroupTemplate

Action Links are actions you can do in chatter posts (e.g. API call, document download, UI redirect) by clicking a button on the related chatter post.

Action Links are grouped into Action Link Group, so you can choose which action you want to play:

You may think that these actions comes to configuration and some sort of layout, but it is part configuration and part Chatter API call.

Action Links are grouped into Action Link Groups but this is not the object that will be configured.

In fact we talk about Templates (Action Link Group Template and Action Link Template): we define template actions rather than the actual actions we’ll be executing.

The template defines the actions you want to apply to a Chatter feed: when you want to apply the group of actions to a feed, we’ll make an API call to get the “instance” of the actions to be linked to the feed.

Let’s start creating a Group Template (the object we are inspecting here) clicking on Setup > Create > Action Link Templates:

You can define:

  • Name and DeveloperName
  • Category (position of the action buttons in the feed)
  • Number of execution allowed
  • Hours untile the action expires

Once a group is published it cannot be modified anymore.

Let’s query the object:

select id, DeveloperName, IsPublished, MasterLabel  from ActionLinkGroupTemplate

Let’s define the actions:

With the following main fields (more details here):

  • Type of Action (API, API Async, UI, Download)
  • Endpoint of the action (in this example a simple request bin)
  • HTTP Method
  • HTTP Request Body
  • HTTP headers
  • Position among other buttons
  • Label (you can choose between some presets and a custom label)
  • Visibility

Consider that URL, request body and headers can have standard and custom binding values (you can for example pass the current User ID or a custom binding value).

These are the actions defined:

To use them we need a valid Session ID, a call to the /connect/action-link-group-definitions/ API endpoint and a call to Chatter API to send a feed.

We’ll be doing things manually (we could use Workbench, but we like to get our hands dirty!).

First we get a valid OAuth Session ID.

Click on Setuo > Create > Apps click on New button in the Connected Apps section; we only need to setup the middle section:

to get access to Chatter API.

This is what you get:

This application will be online in 10 minutes at most.

Let’s make a REST call to get a valid token using the OAuth Password Flow (details here ):

POST https://login.salesforce.com/services/oauth2/token
    Headers:
        Content-Type: application/x-www-form-urlencoded
    Body:
        grant_type=password&client_id=[APP_CONSUMER_KEY]&client_secret=[APP_CONSUMER_SECRET]&username=[USERNAME]&password=[PASSWORD+TOKEN]

The response returns the Session ID (athorization token) we’ll use to get a valid Action Group Id from this REST call:

POST https://xxx.salesforce.com/services/data/v34.0/connect/action-link-group-definitions/
    Headers:
        Authorization: Bearer [SESSION_ID]
        Content-Type: application/json
    Body:
        {"templateId":"07g24000000CaTc","templateBindings":[]}

Where templateId is the ID of the Action Link Group Template (you can query for it or get it in the configuration section of the template), and templateBindings is a list of objects (with “key” and “value” fields) for custom bindings.

This call will return an instance of the template:

{
  "actionLinks": [
    {
      "actionUrl": "https://requestb.in/11jyqzq1",
      "createdDate": "2015-08-14T20:41:42.566Z",
      "excludedUserId": null,
      "groupDefault": false,
      "headers": [
        {
          "name": "content-type",
          "value": "application/json"
        }
      ],
      "id": "0An240000004FSDCA2",
      "label": "Salute!",
      "labelKey": "None",
      "method": "HttpPost",
      "modifiedDate": "2015-08-14T20:41:42.566Z",
      "requestBody": "{"message": "Hello!", "from":"{!userId}"}",
      "requiresConfirmation": false,
      "templateId": "07l24000000GmbgAAC",
      "type": "Api",
      "userId": null
    },
    {
      "actionUrl": "https://requestb.in/11jyqzq1",
      "createdDate": "2015-08-14T20:41:42.566Z",
      "excludedUserId": null,
      "groupDefault": false,
      "headers": [
        {
          "name": "Content-Type",
          "value": "application/json"
        }
      ],
      "id": "0An240000004FSECA2",
      "label": "Insult!",
      "labelKey": "None",
      "method": "HttpPost",
      "modifiedDate": "2015-08-14T20:41:42.566Z",
      "requestBody": "{"message":"Bad Word", "from":"{!userId}"}",
      "requiresConfirmation": true,
      "templateId": "07l24000000GmblAAC",
      "type": "Api",
      "userId": null
    }
  ],
  "category": "Primary",
  "createdDate": "2015-08-14T20:41:42.566Z",
  "executionsAllowed": "Once",
  "expirationDate": null,
  "id": "0Ag240000004FSNCA2",
  "modifiedDate": "2015-08-14T20:41:42.566Z",
  "templateId": "07g24000000CaThAAK",
  "url": "/services/data/v34.0/connect/action-link-group-definitions/0Ag240000004FSNCA2"
}

Now we can use the id to post the action with a feed:

POST https://xxx.salesforce.com/services/data/v34.0/chatter/feed-elements
    Headers:
        Authorization: Bearer [SESSION_ID]
        Content-Type: application/json
    Body:
        {
          "body": {
            "messageSegments": [
              {
                "type": "Text",
                "text": "What do you want to say me?"
               }
            ]
            },
          "subjectId": "me",
          "feedElementType": "FeedItem",
          "capabilities": {
            "associatedActions": {
              "actionLinkGroupIds": ["0AgRR0000004CTr0AM"]
            }
          }
        }

Once you click on a button, the action is executed and no more action is possible:

The same sequence can be done using Apex and the ConnectApi library:

// Get the action link group template Id.
ActionLinkGroupTemplate template = [SELECT Id FROM ActionLinkGroupTemplate WHERE DeveloperName='Say_Hello'];


// Create ActionLinkTemplateBindingInput objects from the map elements.
List bindingInputs = new List();
/*
// Add binding name-value pairs to a map: our action does not have custom bindings
Map bindingMap = new Map();
bindingMap.put('aBinding','aValue');
for (String key : bindingMap.keySet()) {
    ConnectApi.ActionLinkTemplateBindingInput bindingInput = new ConnectApi.ActionLinkTemplateBindingInput();
    bindingInput.key = key;
    bindingInput.value = bindingMap.get(key);
    bindingInputs.add(bindingInput);
}
*/

// Set the template Id and template binding values in the action link group definition.
ConnectApi.ActionLinkGroupDefinitionInput actionLinkGroupDefinitionInput = new ConnectApi.ActionLinkGroupDefinitionInput();
actionLinkGroupDefinitionInput.templateId = template.id;
actionLinkGroupDefinitionInput.templateBindings = bindingInputs;

// Instantiate the action link group definition.
ConnectApi.ActionLinkGroupDefinition actionLinkGroupDefinition = 
ConnectApi.ActionLinks.createActionLinkGroupDefinition(Network.getNetworkId(), actionLinkGroupDefinitionInput);

This is what the bin has received:

Imagine you can use this feature for allowing selected users to partecipate to surveys/polls or make them doing actions to monitor their behavior.

[Salesforce] The Sobject Crusade: AccountFeed

Back to the Sobject Crusade list.

Source: AccountFeed

This represents a single feed item on the Account record detail page (chatter feed).

It tracks different kind of feeds:

ActivityEvent—indirectly generated event when a user or the API adds a Task associated with a feed-enabled parent record (excluding email tasks on cases). Also occurs when a user or the API adds or updates a Task or Event associated with a case record (excluding email and call logging).

For a recurring Task with CaseFeed disabled, one event is generated for the series only. For a recurring Task with CaseFeed enabled, events are generated for the series and each occurrence.

  • AdvancedTextPost: created when a user posts a group announcement
  • ApprovalPost: generated when a user submits an approval
  • CanvasPost: a post made by a canvas app posts on a feed
  • CollaborationGroupCreated: generated when a user creates a public group
  • ContentPost: a post with an attached file
  • CreatedRecordEvent: generated when a user creates a record from the publisher
  • DashboardComponentAlert: generated when a dashboard metric or gauge exceeds a user-defined threshold
  • DashboardComponentSnapshot: created when a user posts a dashboard snapshot on a feed
  • LinkPost: a post with an attached URL
  • PollPost: a poll posted on a feed
  • ProfileSkillPost: generated when a skill is added to a user’s Chatter profile
  • QuestionPost: generated when a user posts a question
  • ReplyPost: generated when Chatter Answers posts a reply
  • RypplePost: generated when a user creates a Thanks badge in Work.com
  • TextPost: a direct text entry on a feed
  • TrackedChange: a change or group of changes to a tracked field
  • UserStatus: automatically generated when a user adds a post. Deprecated

To enable chatter feed tracking, go to Setup > Chatter > Feed Tracking and select the Account object and the fields you want to track.

Let’s take this account:

We have an AccountFeed of type TrackedChange and another one of type TextPost.

By querying for AccountFeed:

Note that the query includes the subquery (SELECT Id, FieldName, NewValue FROM FeedTrackedChanges), that returns, only for the TrackedChange record:

[
    {
        "Id":"0D624000009RROlCAO",
        "FieldName":"Account.Phone",
        "NewValue":"(650) 450-8812"
    },{
        "Id":"0D624000009RROmCAO",
        "FieldName":"Account.Fax",
        "NewValue":"(650) 450-8822"
    }
]

which tracks the fields change that originated the AccountFeed record.

N.B. Note we could have used the FeedItem object as well:

SELECT id, Type, Title, Body, Visibility, likecount, NetworkScope, (Select Id, FieldName, NewValue From FeedTrackedChanges) from Feeditem where ParentId='00124000003vaBu' 

[Salesforce / Trailhead] The beginning of your Force.com journey

a{color:red !important;}

Few days ago the Salesforce team released 4 new Trailhead modules, and I decided finally to have a look at it…with my style.

What is my style?

I may say “all in” or “all or nothing” style.

I decided to do all the modules and see which topics were covered (and how deeply).

With year of Force.com development it’s been quite easy for me to complete in few hours all the modules, but I haven’t earned all the points available (I did some mistakes when answering to questions) and I must admint I also learned something (expecially in modules I don’t play a lot in my job).

After 16 modules I have to say this is a really good starting point to start learning the basics of the Force.com platform, and sometimes the documentation goes deeper than you could expect, covering important aspects that sometimes you find out only after months of “real world” practice.

The Trailhead modules page lists all the modules in alphabetical order, but you can follow the 3 steps on the Trailhead main page to have a better study order.

Recently some cool modules have been added:

  • Process Automation: you learn the basics of process automation and the new Process Builder and Visual Workflows tools, cool ways to get your complex processes up and running in few clicks!
  • Chatter Basics: this useful module teaches the basics of setting up Chatter on your org to improve social collaboration
  • Lightning Components: this is my favorite modulo above all, I love Lightning Components and can’t wait to see them out of the Beta stage. Learn base and advanced aspects of this new powerful framework
  • Visualforce Mobile: learn how to create slick and smooth visualforce pages on the Salesforce1 mobile platform

This is the complete list of available modules:

And (awesomely) these are “can’t wait” upcoming modules:

  • Reports & Dashboards: Build real-time reports and charts to visualize key business metrics
  • Apex Integration Services: Integrate with external apps using Apex REST and SOAP services
  • Asynchronous Apex: Write more efficient Apex code with asynchronous processing
  • Visualforce & JavaScript: Use JavaScript to enhance and customize your Visualforce pages
  • App Deployment: Learn best practices for team app development and lifecycle management

Stay tuned for more modules!

I’m gonna definitely suggest all my Company’s interns to start learning Force.com using Trailhead, a funny and awesome way to learn the Force!

And once for all:

Powered by WordPress & Theme by Anders Norén