1

I want a "Reopened" status for particular record types in my org. However, I don't want users to be able to set the status directly - this status can only be set through a particular visualforce page.

If a case is re-opened, users would see the status as reopened but they would only be able to select normal values for status through the picklist.

How is this possible with Salesforce?

1

You just need some simple Apex Code.

Shared Code

public class CaseControl {
  public static Boolean allowReopen = false;

  public static void verifyReopen(Case[] prior, Case[] current) {
    if(!allowReopen) {
      for(Integer index = 0, size = current.size(); index < size; index++) {
        if(prior[index].Status == 'Closed' && 
           current[index].Status <> 'Closed') {
          current[index].addError('Please use the Visualforce page to reopen this case.');
        }
      }
    }
  }
}

Trigger

trigger verifyReopen on Case (after update) {
  CaseControl.verifyReopen(Trigger.old, Trigger.new);
}

Then, when you want to allow a reopen, say, in your Visualforce code...

Case Reopen

public PageReference reopenAndSave() {
  CaseControl.allowReopen = true;
  caseRecord.Status = 'Reopened';
  update caseRecord;
  return new ApexPages.StandardController(caseRecord).view();
}
| improve this answer | |
  • did you mean caseRecord.Status = 'Reopened' ? – cropredy Apr 30 '16 at 6:00
  • @cropredy Yeah, I thought I changed it. Silly me. – sfdcfox Apr 30 '16 at 14:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.