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
case commentscase comments 

Re-Open Case Button

I'm trying to create a button to put on the customer portal layout to allow them to re-open a closed case.  I've created a custom button that calls on a VF page.  Everything seems to work fine, but the customer can click that button at anytime, even for a non closed case.  What kind of  logic can I put in to only allow the button to be executed for a closed case?
The simple answer would be to change the record type of the closed case to something else and put the button on the new record types page layout, but I can't chnage any record types for our own business process reasons. 
Any help would be greatly appreciated.  Thanks.

public class ReOpenExtension {
    public ReOpenExtension(ApexPages.StandardController controller){
    Case c = (Case)controller.getRecord();
    c.Status = 'In Progress';
}
public static void testMethodtest() {
    Case c = new Case();
    ApexPages.StandardController controller = new ApexPages.StandardController(c);
    ReOpenExtension extension = new ReOpenExtension(controller);
    System.assertEquals(c.Status,'In Progress');
    }
}


<apex:page standardController="Case" extensions="ReOpenExtension">
<apex:form >
<h1> Re-Open Case Form</h1>
<apex:pageblock title="{!case.CaseNumber}">
<apex:pageblocksection columns="1" >
<apex:inputtextarea value="{!case.Re_Open_Case_Reason__c}" cols="100" rows="5"/>
</apex:pageblocksection>
<apex:pageblockButtons >
               
                <apex:commandbutton action="{!save}" value="Save"/>
               
                <apex:commandbutton action="{!cancel}" value="Cancel"/>
            </apex:pageblockButtons>
</apex:pageblock>
</apex:form>

</apex:page>
Best Answer chosen by case comments
Sonam_SFDCSonam_SFDC
In the following

public ReOpenExtension(ApexPages.StandardController controller){
    Case c = (Case)controller.getRecord();
    c.Status = 'In Progress';
}

Would it help if you first compare the current Case Status to contain the word "Closed"

If it is there - then only change to in progress else throw a message - can aready open and exit?