Last Updated on November 24, 2020 by Rakesh Gupta
What is a Custom Metadata Type? Why should one use it? How should one use it? And, last but not least, how is Custom Metadata Type related to, or different than, Custom Object? Well, let us explore these concepts together!
Custom Metadata Type is similar to a custom object – it allows application developers to create custom sets of data, as well as to create and associate custom data with an organization. All custom metadata type data is available in the application cache. As a result, it allows efficient access to the data without the cost of repeated queries (SOQL) to a database.
Custom Metadata Type is mainly used to store information that will be frequently accessed from Apex code. Custom Metadata Type performs better than a custom object because it is available in cache; and therefore, it does not have to be queried. The other difference, which you will notice between the custom metadata type and a custom object, is the difference in the suffix. Custom Metadata type has __mdt suffix at the end of the custom metadata type, as opposed to the usual __c for custom objects. As of the Summer’17 release, custom metadata is not yet available in Process Builder. However, it is currently available in Visual Workflow.
Business Use Case
Let us start with a business use case. Pamela Kline is working as System administrator at Universal Containers. At UC they are using Chatter extensively for internal communication to manage Sales and Support. Business Users are often using Chatter to ask help from Internal Salesforce team regarding how to use some feature.
Pamela has received a requirement to auto-create a case whenever a new Chatter post (not a comment) contains a keyword word. She received a list of keyword words (almost 11 words) from her manager. Pamela’s task is to ensure that only a single case is created even if Chatter posts contain numerous keyword words.
Solution for the above business requirement
There are various ways to solve preceding business requirement. Few of them are following:
- Create an Apex Trigger on the FeedItem object – We will work on this option in our upcoming Apex Series.
- Use all 11 keywords in a Process Builder (On feedItem object) entry criteria and use the Create a Record action to auto-create a case. The problem with this approach, however, is that if, after few days, the business wants to add or remove a few keywords, then you have to start from scratch again.
- Use Custom Setting to store the keywords and then use Process Builder to manage your logic.
- Use Custom Metadata Type to store the keywords and then use Visual Workflow and Process Builder to manage your logic. Custom metadata provides the flexibility to add or remove keywords without having to change your Process definition or Flow.
List of Keywords: – Ohana; Salesforcehelp; help; TrailheaDX, MidwestDreamin, SoutheastDreamin, IndiaDreamin, TDX17, SalesforceOhana, JDF17, dreamOlé
To solve the preceding business requirement, we will take the 4th approach. We will use – (i) custom metadata type to store the keywords; use (ii) Flow to compare the keywords with the Chatter post body; and, use Process Builder to launch the Flow. Perform the following steps to solve the preceding business requirement:
- To create a new custom metadata type, navigate to Setup (Gear Icon) | Setup | PLATFORM TOOLS | Custom Code | Custom Metadata Types and click on the New Custom Metadata Type button. Now fill the form as mentioned in the following screenshot:
- Once you are done, click on the Save button.
- Create a Text field Keyword to store the words that you want to track in a Chatter post and make this field a required field. At the end, the Chatter Keyword custom metadata type should look like what is shown in the following screenshot:
- The next step is to insert a few records into the custom metadata type. To do that, click on the Manage Chatter Keywords button on the custom metadata type detail page, and then click on New to insert some records, as shown in the following screenshot:
- The next step is to create a Flow to implement the business requirement, i.e. create a case from keyword word used in a Chatter post. To do that, navigate to Setup (Gear Icon) | Setup | PLATFORM TOOLS | Process Automation | Flows. Click on the New Flow button; it will open the Flow canvas for you. Create the variables in the Flow, as shown in the following table:
Name Variable type Object type Input/Output type VarT_Feedbody Text Not applicable Input and Output VarT_FeedItemId Text Not applicable Input and Output SovKeyword SObject variable Chatter_Keyword__mdt Input and Output SOCVKeywords SObject Collection variable Chatter_Keyword__mdt Input and Output We are passing the value to VarT_FeedItemId through Process Builder.
- The next task is to get all the Chatter post body. For this, we will use the Record Lookup element. To do this, drag and drop the Record Lookup element onto the canvas; it will open a new window for you, where you have to enter the following details:
- Name: Enter the name for the Fast Lookup element. In this case, enter Get the Feedbody as the name.
- Unique Name: This will be auto-populated based on the name.
- Description: Enter a meaningful description.
- Look up: Select the object for which you want to search the records. In this case, select FeedItem. The next task is to define the search criteria; for this select Id equals VarT_FeedItemId
- Assign the record’s fields to variables to reference them in your flow: Optionally, you can save the fields’ values into variables, so you can use them later in the Flow. Save Body into the VarT_Feedbody variable.
- The next step is to get all the keywords from custom metadata type. For this, we will use the Fast Lookup element. To do this, drag and drop the Fast Lookup element onto the canvas; it will open a new window for you, where you have to enter the following details:
- Name: Enter the name for the Fast Lookup element. In this case, enter Get all keywords as the name.
- Unique Name: This will be auto-populated based on the name.
- Description: Enter a meaningful description.
- Look up: Select the object for which you want to search the records. In this case, select Chatter_Keyword__mdt. The next task is to define the search criteria; for this, select Keyword__c as the field, the does not equal operator, and the global constant {!$GlobalConstant.EmptyString} as the value.
- Variable: Use the SObject Collection Variable SOCVKeywords. Do not forget to select the Assign null to the variable if no records are found checkbox. Finally, select the fields whose values you want to store in the SObject variable or SObject Collection variable; in this case, select Keyword__c.
- The next task is to check whether the SObject Collection variable contains any Keywords or not. It might be possible, there is no record inserted to custom metadata type yet. To check this, we will use the Decision element. To do that, drag and drop the Decision element onto the canvas; it will open a new window for you, where you have to enter the following details:
- Name: Enter the name Check SObject Collection Variable Size
- Unique Name: This will be auto-populated based on the name.
- Description: Enter a meaningful description.
- Outcome: Enter the name Not Null as EDITABLE OUTCOME, Select the SObject Collection variable SOCVKeywords as Resource, then is null Operator, and the {!$ GlobalConstant.False} global constant as the value.
- If the SObject Collection variable is not null, that means that it contains some banned words. We will use the Loop element to extract records from the SObject Collection variable (SOCVKeywords) and store it to the SObject variable (SovKeyword). Click on the Palette tab and drag and drop the Loop element onto the Flow canvas. Map it according to the following screenshot:
- The next task is to check whether VarT_feedbody – i.e. whether the Chatter post – contains any keywords or not. To check this, we will use the Decision element. To do that, drag and drop the Decision element onto the canvas; it will open a new window for you, where you have to enter the following details:
- Name: Enter the name Lookup for Keywords
- Unique Name: This will be auto-populated based on the name.
- Description: Enter a meaningful description.
- Outcome: Enter the name Found as EDITABLE OUTCOME, Select the variable VarT_Feedbody as Resource, then Contains Operator, and {!SovKeyword.Keyword__c} as the value
- If the VarT_Feedbody variable contains a keyword, then we have to create a new case. Click on the Palette tab and drag and drop the Record Create element onto the canvas; it will open a new window for you, where you have to enter following details:
- Name: Enter the name for the Record Create element. In this case, enter Create a new case as the name.
- Unique Name: This will be auto-populated based on the name.
- Description: Enter a meaningful description.
- Create: Select the Case object. The next task is to assign the value or resource to the object fields (data types must match). To assign a value to multiple fields, click on the Add Row link. Map the fields according to the following screenshot:
- Use the connector to connect the elements used in the Flow. Finally, your Flow will look like the following screenshot:
- Save the Flow (Type: – Autolaunched Flow) with name Chatter Post Keywords Tracking and close the canvas. Don’t forget to Activate the Flow.
Launch a Flow from Process Builder
Our next task is to create a Process Builder on the FeedItem object to start a Flow. To create a Process Builder on the FeedItem object follow the below instructions
1. Click on Name | Setup | App Setup | Create | Workflows & Approvals | Process Builder
2. To create a new process from scratch, click on the New Button available on Process Management page. A popup will appear where you have to enter the Name (Use Create a case from Chatter Post as a name), API Name and Description as shown in the below screenshot:
3. Click on Object node to add object and then select the FeedItem object. For the entry criteria, Select only when a record is created, as shown in the below screenshot. Once done, click on the Save button.
4. The next task is to add Process Criteria. To do this click on Add Criteria, enter Name, Type of action and set filter conditions as shown in the following screenshot:
5. The next step is to add an Immediate action to Process. Click on Add Action (Under Immediate actions), Select the type of action to create (In our case Flows). Use Field Picker to choose the field [FeedItem].Id, as shown in the following screenshot:
6. Once done, click on the Save button, it will redirect you to Process canvas. Finally, the Process will look like the following screenshot:
Don’t forget to active the Process by clicking on the Activate button.
6 thoughts on “Getting Started with Process Builder – Part 69 (Auto Create a Case From Keyword Word Used in Chatter)”
Scott Fletcher
Thanks for this very helpful walk-through. I have a use-case where I’m performing some logic on Case in Process Builder and before the process goes through several decision nodes, I want it to check whether the case Origin is one of several origins stored in custom metadata. If the output of that check is TRUE, then the process should proceed through the decision nodes. I think this is not possible however as it does not appear that Visual Workflow supports passing output variables back to Process Builder. Any alternative ideas for handling this use-case without code?
Rakesh Gupta
You are right, it is not possible to pass the output variables back to Process Builder. How about implementing your logic in the Visual Workflow, after Decision element.
SunshineAsmi
Would that not be hardcoding.
I created one more Custom field
1. Keyword
2.Service Keyword
FeedTags are:
1. Label=Sales, Keyword= Sales; Service Keyword= Null
2. Label=Service, Keyword= Null; Service Keyword= Service
Now I am using it in Flow Decision LookForFeeds, I created two separate outcomes –> which will have different case creation.
Still no case are getting created
Rakesh Gupta
As I said earlier you do not need Flow or anything else except Process Builder. As you are using Custom Metadata Types, you do not need to hardcore any thing.
SunshineAsmi
Can we create different types of cases using different keywords using same process.
For example:
1. Keyword Sales : Create Case of Type Sales
2.Keyword Support: Create Case of Type Support
Rakesh Gupta
Yes, it is possible to create different types of cases using Process Builder and Custom Metadata Types.
Create another branch in the same process that’s it.
For example,
Criteria Node 1:- if Keyword Sales: Create Case of Type Sales
Criteria Node 2:- if Keyword Support: Create Case of Type Support
Also, check out this article Getting Started with Process Builder – Part 72 (Execute Actions on More Than One Criteria)