Create case comments in Salesforce1 app – with out coding!

salesforce1

UPDATE: Added additional steps (as a separate section to this blog) to clear the deleted tasks from the users recycle bin. This step involves some coding (actually one line of code), so use it as you see fit. 

One of the pet peeves of Salesforce1 app users is that you can’t add comments to a case using Salesforce1. A couple of ideas to enable this is already out there in idea exchange
https://success.salesforce.com/ideaView?id=08730000000kxxaAAA
https://success.salesforce.com/ideaView?id=08730000000kxtxAAA

Some have tried to solve this using coding as detailed here – http://clicksandcode.blogspot.com/2014/07/case-comment-in-salesforce1.html.

In this blog, I am presenting a way of achieving this using only declarative tools. I will use a combination of quick actions, process builder and flow to achieve this requirement. The high level approach is to provide a quick action in the case object for the user to create a task with comments and then use this task comments to create case comments. Once case comments are created, the task and any associated task feed that it creates will be deleted. The creation of the case comments and deletion of task and task feed will be performed using process builder process and an auto launched flow.

It is assumed that you have basic working knowledge of Flow and Process Builder. If not, please get yourself up to speed on Process Builder and Flow before proceeding further. Some useful links provided below

Process builder Trailhead – https://developer.salesforce.com/trailhead/business_process_automation/process_builder

An excellent blog series by Rakesh Gupta – https://rakeshistom.wordpress.com/2015/02/13/getting-started-with-process-builder-part-1-auto-create-a-record/

Nice visual workflow video tutorials by Brian Kwong
http://thewizardnews.com/2015/03/21/wizards-apprentice-visual-workflow-getting-familiar/

Step 1
Create a pick list entry for task type, say ‘Case Comments’

New Task Type

Step 2
Create a new quick action in the case object. For e.g., ‘Case Comments’. This quick action will create a task record for the case object

Case Comment quick action

Step 3
Only place the ‘Comments’ and ‘Public’ field in the layout

Layout for case comment quick action

Step 4
Pre-define the following fields so that the user doesn’t have to deal with them

Pre-defined fields

Step 5
Add this quick action to the ‘Actions in the Salesforce1 Action bar’ panel of your page layout(s).

Add action to page layout

Step 6
Create an ‘auto launched flow’. For e.g., name it ‘Case Comments’

Step 7
Create a ‘Sobject Variable’ in the flow of type ‘Input and Output’, for retaining task object fields. For e.g., name it ‘sTask’.

sTask SObject variable

Step 8
Create another SObject variable in the flow of type ‘Private’ for retaining Case object fields. For e.g., name it ‘sCase’

Case object

Step 9:

Create another Boolean variable of type ‘Input/Output’ for certain decisions within flow (more on this later). For e.g. name it ‘vFeedItem’

Feed Item variable

Step 10
As a first step in the flow, create a ‘Decision’ step to decide if the flow needs to create case comments or it should delete task feed. We will look in to the significance of this step when create a process builder process. For now, create a decision step as below. This decision step has two outcomes ‘Feed Item Flow’ (when vFeedItem=true) and ‘Case comment Flow’ (when vFeedItem=false)

Case create flow

Outcome: Case comment flow

Feed Item flow

Outcome: Feed Item flow

Step 11
Create a ‘Record Lookup’ step to look up Case details based on the task record. Connect this step to the ‘Case Comment flow’ outcome of the decision step

Case Lookup

Step 12
Create a ‘Record Create’ step to create case comments from the task comments field. Also set the isPublished field as shown in the screen shot. Connect this step to the ‘Record Lookup’ step for case object created above.

Case comment create

Step 13
Create a ‘Record Delete’ step for ‘Feed Item’ object. This step is to delete the task feed that gets automatically created when a task is created. You don’t need this step if you haven’t enabled task feed tracking. Connect this step to the decision step created earlier with ‘Feed flow item’ as the outcome.

Task Feed tracking

Step 14
Create a ‘Record Delete’ step for ‘Task’ object to delete the task that was created by user using the Salesforce1 app. Connect this step to ‘Task feed delete’ step created above (or decision step in case you haven’t enabled task feeds).

Delete task

Step 15
Finally, make the decision step as the start element and activate the flow. Your flow should look something like this..

Full flow

Step 16
Now, create a new process builder process for the task object. Only trigger this process when tasks are created

Task object process builder

Step 17
Add a decision step to check whether the created task is of type ‘Case Comments’ (remeber the custom task type that you created in step 1)

Process Builder decision

Step 18
Add an immediate action to the ‘true’ branch of the decision step to call the flow created above. Remember to pass the task object as reference as well as the variable ‘vFeedItem’ as ‘false’. This step will create the case comments from the task comments

Create case comments

Step 19
Add a schedule action to execute after the task has be created. You would do that by creating a schedule action to execute ‘0’ days after task created date

Schedule action

Step 20
Add an action to the schedule created above to call the flow. Remember to pass the task object as reference as well as the variable ‘vFeedItem’ as ‘true’. This step will delete the task feed automatically created by the system as well as the task that was created by the user

Delete task feed

Step 21
Activate the flow and now you are all set. Now users can directly add case comments using Salesforce1.

Salesforce1 app

Some caveats:

  • Email notifications are not sent to the contacts automatically. You can add an additional ‘Send email’ step in your flow to send notification to the contact on the case, if your requirement is to send email notification for certain comments.
  • This process will only let you create new comments. It doesn’t let you edit or delete comments that you already created.
  • I haven’t tested this extensively in a production environment. Please use at your own risk while implementing in your landscape.

UPDATE: Additional steps for clearing the deleted tasks from user’s recycle bin:

Please note that the above process deletes the tasks and they land in the user’s recycle bin. If you don’t want to clutter the recycle bin, you can use the below steps to permanently delete these tasks. Yes, this steps involves some coding, but I wanted to leave an option in case you want to implement this in your org.

Step 1
Go to Setup->Develop->Apex Classes->New. Type the below code and save


global class EmptyRecycleBinForAnObject {
@InvocableMethod
public static void emptyRecycleBin(List<Id> ids){
Database.emptyRecycleBin(ids);
}
}

Step 2

Go to your flow and include a step below the ‘Record Delete’ for task object (created through Step 14 above) to call the Apex class created above (You should find your apex class already appearing in the pallet under ‘Apex’). For input, assign the task ID to the ‘ids’ parameter as shown below.

Delete Recycle bin

Now, these two steps should take care of any clutter that gets created in the users recycle bin. Of course, you would need a test class to get this to production as well, so here is a sample test class that you can use (the test class is bigger than the actual class!)


@isTest
public class EmptyRecycleBinForAnObjectTest {
@isTest static void test_method_one(){
Account acc = new Account();
acc.name = 'test for empty bin';
insert acc;
//get the account id
List<Account> accs = [SELECT Id FROM Account WHERE name='test for empty bin'];
List<Id> Ids = new List<Id>();
for(Account a:accs){
Ids.add(a.id);
}

Database.delete(acc);
EmptyRecycleBinForAnObject.emptyRecycleBin(Ids);
//Check recycle bin, should have no records
Database.GetDeletedResult trash = Database.getDeleted('Account', Datetime.now().addHours(-1), Datetime.now());
System.assert(trash.getDeletedRecords().size()<=0);

}
}

Summary

Salesforce1 app is an excellent mobile app to support your business processes on the go! However, not all functionality that is available in the full site is currently available in Salesforce1. This gap is continuing to reduce with every new release and till then, we can use the power of the Salesforce1 platform to declaratively enable some of these functions. In the next blog, I will share some more similar use cases for Salesforce1.

Now, the fine print.. At the time of writing this blog, I am employed with Salesforce as a Success Architect. However, any code samples and declarative approach provided here are purely for experimental purposes and comes with no warranty or support. Matter of fact, all opinions and approach provided in this blog are purely my own and has nothing to do with my employer. It is assumed that you have the right Salesforce configuration and coding skills and will use this tool as you see fit in your landscape. The primary purpose of this article is just to share the knowledge and my own experience. Nothing more, nothing less. Use this approach at your own risk

Advertisements

17 thoughts on “Create case comments in Salesforce1 app – with out coding!

    • Puja – thanks for taking time to respond. I see your point but I also see some issues with that idea

      1) How will you decide which case feed item needs to be added as comment and which not?
      2) What happens if the org is not enabled for chatter? The approach I have detailed here works for orgs that don’t have chatter enabled or don’t adopt chatter as much (https://help.salesforce.com/apex/HTViewHelpDoc?id=actions_with_or_without_chatter.htm&language=en_US)

      Like

      • What a fabulous teacher you are AND you find workarounds to known issues. GREAT!!!

        I have zero experience in Flow and only marginal experience yet decent success in PB. I was holding my breath and going through each step with great ease until step 18 “Only active autolaunched flows can be launched by a process. Processes can launch only active flows that don’t contain screens.” (or perhaps I goofed in Step 6)… My flow will not autolaunch . I copied your screen shots and steps verbatim – or so I thought. Any ideas? (I know that’s a mouthful and you recommend at the top to get familiar with links).

        Fondly,
        Virginia

        Like

      • Virginia, thank you for the kind words. Can you check if your flow is active (Setup->Flow->- activate. If your flow is already active, please check if you chose ‘auto launched flow’ as flow type when you saved the flow.

        Like

  1. yes, active or deactivated, I have tried both. For some reason I am given the prompt in flow details that autolauch is not an option because a ‘window’ is used. (I will dig up actual text tomorrow.) would post screenshot but not sure how on here? THank you kindly kumarrk21 . again, you’ve given me very exciting hope that I am close to providing a great need for my org.

    Like

    • in checking the Flow Properties for Case_Comments, Type “autolaunch” is greyed out with the prompt “Requires User interaction because it has one or more screen” etc. Does this help troubleshoot?

      Like

      • Looks like you have placed a screen element in you flow. You may want to check your flow with the steps I have shown above, you should only have Decision, Record Create, Record Delete and Record lookup elements in your flow. Also, you should make the decision step as the start element if you haven’t already.

        Like

      • those are definitely the only elements I have. I went through and double checked all your steps. Will delete flow and start from scratch. You are kind to assist.

        Like

    • Hi again! Wondering if you could help – again? 😉 I’ve started to roll out this workaround to a few power users and everyone came back reporting an error. When I made them Salesforce Sys Admins (for testing this) they were able to add comments no problem. Would you happen to know where in their profile I make the edit to allow them to add comments on the cases via mobile?

      Fondly,
      Virginia

      Like

      • Virginia.. there is no specific permissions for using this in mobile. If your users have access to create and delete tasks on cases, create and delete feed items and create case comments in their profile, this should work. What is the error they are receiving?

        Like

      • Logged in under their normal profile they can get to the new comment screen on SF1. They can type in the comment. When clicking save they get : Please Contact Salesforce Customer Support Error ID: 1042194384-43606 (1192810671)

        When I made two of them Administrators , their comments saved just fine.

        This is how it was reported to me. Then I logged into their mobile sites and experienced it first hand.

        Curious, yes?

        Like

  2. fixed. thanks for talking it aloud with me.. these users didn’t have the ability to delete comments. I could not readily see in permissions how to grant this. I removed “delete comments” from your flow and it works fine now.

    Have you been given a crown yet for this workaround you created? Surprised more from the community haven’t chimed in here yet – as many complaints as there are regarding this lack of functionality. 🙂

    Like

  3. I was able to see and enter a Case Comment in SF1, which is awesome. The Record Create step is failing because – I believe – I can’t set the value of the IsPublished field as instructed. The sTask value of “IsVisibleInSelfService” isn’t available. Any idea why?

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s