function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Volker_factory42Volker_factory42 

Closing a Case with Apexcode

I need to have an apex-class which can close open Cases. 

I tried to update Case.status = "Closed", but the Case is not closed after this update. 
Case.isclosed is not writeable. Is there a possibility to close a case with apex? 

i.e. like Database.leadconvert() ? 

Best Answer chosen by Admin (Salesforce Developers) 
soofsoof

I believe you're doing everything right.  Let's see... after updating the status to 'Closed', is it changing back or staying as 'Closed'?  What do you get if you query the IsClosed field after updating?  Is is set to true?  Just wondering if some trigger/workflow is messing w/ your Update operation?

 

The other thing that I can think of is whether the 'Closed' Status picklist value is marked as 'Closed'?  If this doesn't make sense, go to Setup > Customize > Cases > Fields, select the 'Status' field, and see the 'Case Status Picklist Values' list at the bottom of the page.  I don't expect an issue there, but just taking a wild guess...

 

Hope this helps.

 

Thanks.

All Answers

soofsoof

I believe you're doing everything right.  Let's see... after updating the status to 'Closed', is it changing back or staying as 'Closed'?  What do you get if you query the IsClosed field after updating?  Is is set to true?  Just wondering if some trigger/workflow is messing w/ your Update operation?

 

The other thing that I can think of is whether the 'Closed' Status picklist value is marked as 'Closed'?  If this doesn't make sense, go to Setup > Customize > Cases > Fields, select the 'Status' field, and see the 'Case Status Picklist Values' list at the bottom of the page.  I don't expect an issue there, but just taking a wild guess...

 

Hope this helps.

 

Thanks.

This was selected as the best answer
Volker_factory42Volker_factory42

The value "Closed" stays in Statusfield, IsClosed is false. The Picklistvalue "Closed" is marked as Closed.

 

As I understand, if the picklistvalue changes to a "Closed" value, IsClosed and Closeddate should be filled automatically. 

 

I don't know why, but it is working now ;-) I didn't change anything...

 

 

JesseAJesseA

I'm having this same issue. I've updated status to Closed. When I open case status has updated but Close Case button still shows.

oGoblinoGoblin
String closeStatus = [SELECT MasterLabel FROM CaseStatus WHERE IsClosed = true LIMIT 1].MasterLabel;
Case c = new Case();
c.Status = closeStatus;

Something like this.