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 a proper solution for the Close Case button which will give you exact functionality as Salesforce, you have landed in 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.

Solution –

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 the 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 the Lightning Experience.

Please see below the code, https://gist.github.com/avi4r10/812181725cae9526a02071ef75894cc6

Step 4 – Create a custom Button that 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 Salesforce 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.