In Spring’14 release Salesforce.com comes with a new feature called as Topics for Objects, So we can organize records by using topics same as Chatter. Topics help to organize records in a better way and make search easier for you. It also increases records, post and comments visibility. For example, if you’re working on an Opportunity for an Account Universal Containers, you might want to add the hashtag topic #UC or #Universalcontainers in Opportunity record. Anyone can click on these topics to find out more information about Universalcontainers and see what people and groups are talking about Universalcontainers, you can also find all records tagged with topic Universalcontainers, as shown in the below screenshot
I have never found any apps or out of the box solution to add a Topic to multiple records. In this article we will develop an app for similar functionality without using code.
Business Use Case
People in Universal Container are using Topics to organize records. Management in Universal Container wants to develop an application so that their business users can add a topic to multiple records without navigating screen to screen. In this demo I will add Topic to all Opportunity records based on Their AccountID. For example add topic Universalcontainer to all opportunity records those belongings to Account “Universal Containers“.
Solution for the above business requirement
To solve above business requirement we will use Visual Workflow and to fire this flow will use Custom Link. Before going ahead with the solution you have to understand about TopicAssignment and Topic Object.
TopicAssignment: – It represents the assignment of a topic to a specific feed item or record.
Topic: – It Represents a topic on a Chatter post or record.
To develop this application follow the below instructions
1) Click on Name | Setup | App Setup | Create | Workflows & Approvals | Flows
2) Click on New Flow, it will open flow canvas for you
3) Drag and drop a Screen Element ( Give the name Enter Search Criteria and Topic Name) onto the window and add two fields with below below detail
Name | Data Type | Required | Description |
Enter Account ID | Textbox | Yes | To get Opportunity records based on AcocuntID, You can change search criteria based on your business requirement |
Enter Topic name | Textbox | Yes | Topic name to Add into records |
It will look like the below screenshot
4) Drag and drop a Record Lookup ( Give the name To Get Topic ID) on the window, To get the topic ID based on Topic Name entered by the user in the previous steps. Under object select Topic, and map Name –> {!Enter_Topic_Name} (Screen Input element Topic Name), and store ID into Text variable {!TopicID} as shown in below screenshot
5) Now Drag and Drop Decision element (Give the name Check Topic existence) on the window to check whether Topic that user entered exist or not, to do that we will use variable {!TopicID}. If the variable {!TopicID} is null = False it means the Topic already exist. You can take help from the following screenshot
6) Next task it to Create the Topic in Salesforce if it’s not exist. Drag and drop a Record Create( Give the name Create Topic) onto the window and map the fields according to below details
- Select Object Topic
- Name= {!Enter_Topic_Name} [ This is nothing but Topic Name that user entered in the first step], Save Id of records into any variable in our case it’s {!TopicID} variable, You can take help from the following screenshot
7) The next task is to get all Opportunities based on AccountID provided by the user. To do that Drag and drop a Fast Lookup ( Give the name Get Opportunity Records based on AccountID ) onto the window to get all Opportunity records and map the fields according to below details
- Select Object Opportunity
- AccountId= {!Enter_Account_ID} [T his is nothing but AccountID that the user entered in the first step], Save Id of records into Sobject Collection variable in our case it’s {!AllOppIDs} . You can take help from the following screenshot
8) Drag and drop a Loop Logic (Give the name To get Single OppID) on the window and extract Opportunity details from Sobject Collection variable and pass it to Sobject variable, You can take help from the following screenshot
9) Our next task is to add OpportunityID and {!TopicID} details into a Sobject variable, so at the end we will add Topic to all Opportunity records. Drag and Drop Assignment Logic (Give the name Add One by One Detail) on the window and a assign value of {!SingleOppID.Id} to Sobject variable variable {!AddDetailsInOneVariable.EntityId} and {!TopicID} to Sobject variable variable {!AddDetailsInOneVariable.TopicId}. You can take help from the following screenshot
10) Drag and Drop Assignment Logic (Give the name Add All Details into one Collection Variable) on the window and assign value from Sobject variable {!AddDetailsInOneVariable} to Sobject Collection variable {!AllinOne} so at the end of for loop (To avoid SOQL limit) it will add Topic to all Opportunity records. You can take help from the following screenshot
11) Finally drag and Drop Fast Create (Give the name AddTopicToRecords) on the window and map the field according to the below screenshot
12) Finally our Flow will look like the following screenshot
13) Save the flow with name Add Topics To Multiple Records and close the canvas.
Add Visual workflow into the home page component
We can call Flow from a custom button, link, sub-flow, Visualforce page, Apex start() or using Flow Trigger workflow action. Here we will call our flow from the homepage component. To do that follow below instruction
1) Create custom link from Name | Setup | App Setup | Customize | Home | Custom Link
2) Add custom link in the Home page component
3) Add Home page component into the Home page layout
It’s time to test this feature
1) In this demo I will add a Topic Universalcontainer to all Opportunity records, those belong to Account Universal Containers
2) To open this app click on Add Topics To Multiple Records link available on the homepage, and fill the details you can take help from below screenshot
3) Click on Next button and you are done. Below is the proof of concept
Note: – I will suggest you to Implement this first on your developer org test it and then move it to Production.