Monday, February 4, 2019

Lightning Experience Close Case Click-Workaround

If you have used Cases in Salesforce, I am sure you’re aware of the Closed Case layout.  This is great, it lets you require the fields that must be filled out before a User can close a Case. 

You might have found many workarounds for this, One of those is Creating a Quick Action

This is good but still it doesn't give us the exact layout and functionality which Salesforce provides for Close Case button out of the box in Classic. 

If you are still in search of proper solution for Close Case button which will give you exact functionality as Salesforce, You have landed on the correct place.

Let's jump into the solution directly.
I will guide step by step how you can achieve exactly the same functionality for Close Case in Lightning Experience.

Requirement - 
  • Exact same Close Case functionality as we have in Classic.
  • Need to add multiple field values to close a case.
  • Field may be dependent on each other
  • Field validation
As you can see from the requirement, these all functionalities is hard to achieve using a Quick action.


Step 1.

Let's get started with our First Step in order to build Close Case Button.

Go to Salesforce Setup => Object Manager => Case => Click on Close Case Page Layouts (In Lightning Experience, In classic Setup => Case => Close Case Page Layout).

Take a note of all the fields present on the Layout and keep the layout as a reference to build your own Close Case Page.

Step 2.

Create FieldSet or FieldSets as per the page Layout, For example if your close case page layout has two sections, create a separate FieldSet for each section.

For Example -

Create One FieldSet for the above, adding all the fields from this section.

Similarly, Create another FieldSet if you another section on your Close Case Layout.

FieldSets will help you to manage this Close Case functionality without changing a single line of code.

In future if you want to add more fields in your close case page, you will just have to add that field in the FieldSet.

Till here, I assume you are ready with your FieldSets.

Step 3.

Create a Visualforce with Case as Standard Controller, lightningStyleSheet = true. This will make the page compatible with Lightning Experience.

Please see below the code,

Have a look at the code above, all the important parts have been properly commented.

Till now, I hope you are ready with your Lightning Visualforce Page.

Step 4. 

Create a custom Button which will open this visualforce page. Please see below the example of that button -

Step 5.

Add this button to Your Case Page layout in Salesforce Mobile And Lightning Experience Action.

That is it. You are ready with your fully functional Close Case Button in Lightning Experience.

I hope you will find this blog helpful. 

If you have any doubt or question, feel free to add in the comment and queries section.


  1. You write this post very carefully I think, which is easily understandable to me. Not only this, but another post is also good. As a newbie, this info is really helpful for me. Thanks to you.
    Tally ERP 9 Training
    tally classes
    Tally Training institute in Chennai
    Tally course in Chennai

  2. This was extremely helpful - thank you so much! One minor issue we ran where the code would hide any picklist values on any field where status is in the label, so we tweaked it to only add the Status styleclass if it was for the actual status field that we fixed by changing:


    1. Yes some changes will require to make it perfect as per your need. This is just a basic work around.