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
Shawn ReichnerShawn Reichner 

Controller Extension for Standard Case Controller

Friends,

I have a Visualforce page that has been created, and what I want to do is when the Visualforce page is submitted to create a case by clicking on the save button on the Visualforce page, I want the user to be redirected to another visualforce page thanking the user for thier submission with the newly created case number.  

I know I will have to create a Standard controller extention, but I am not familiar with this process at all, and any help would be very much appreciated.  

Here is the Visualforce page code I have created, and for our example purposes the VF page for the redirect we will name Thank_You.  

Please help however you can by telling me how to create a custom extentsion to add functionality to redirect to the Thank_You Visualforce page after the standard Save has been completed. 

Thank you so much!

<apex:page standardController="Case">
<img src="{!$resource.AVISPL_Logo2}"></img>
<apex:pageBlock >
<apex:pageBlockSection title="Hello, Thank You For Your Project Request !" columns="1" showHeader="True" collapsible="False">
</apex:pageBlockSection>
</apex:pageBlock>
<apex:form >
<apex:pageBlock tabStyle="Case" title="Impact" >
<apex:pageBlockSection >
    <apex:inputField value="{!Case.Number_of_Users_Affected__c}"/>
    <apex:inputField value="{!Case.Area_s_Affected__c}"/>
    <apex:inputField value="{!Case.Functionality_Affected__c}"/>
    <apex:inputField value="{!Case.Profile_s_Affected__c}"/>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock title="Description Information" >
<apex:pageBlockSection >
    <apex:inputField value="{!Case.Subject}"/>
    <apex:inputField value="{!Case.Driver__c}"/>
    <apex:inputField value="{!Case.Benefit_Of_Change__c}"/>
    <apex:inputField value="{!Case.Reason_For_Change__c}"/>
    <apex:inputField value="{!Case.Description}"/>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock title="Deadlines and Project Status" >
<apex:pageBlockSection >
    <apex:inputField value="{!Case.Target_Deadline__c}"/>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock title="Requesting Department Information" >
<apex:pageBlockSection >
    <apex:inputField value="{!Case.Sponsoring_Department_s__c}"/>
    <apex:inputField value="{!Case.Sponsoring_Dept_GL_Code__c}"/>
    <apex:commandButton value="Submit Change Request" action="{!Save}"/>
</apex:pageBlockSection>
</apex:pageBlock>

</apex:form>
</apex:page>
Best Answer chosen by Shawn Reichner
Vinit_KumarVinit_Kumar
Hi Shawn,

Try below code :-

VF page 
<apex:page standardController="Case" extensions="cseController">
<img src="{!$resource.AVISPL_Logo2}"></img>
<apex:pageBlock >
<apex:pageBlockSection title="Hello, Thank You For Your Project Request !" columns="1" showHeader="True" collapsible="False">
</apex:pageBlockSection>
</apex:pageBlock>
<apex:form >
<apex:pageBlock tabStyle="cse" title="Impact" >
<apex:pageBlockSection >
    <apex:inputField value="{!cse.Number_of_Users_Affected__c}"/>
    <apex:inputField value="{!cse.Area_s_Affected__c}"/>
    <apex:inputField value="{!cse.Functionality_Affected__c}"/>
    <apex:inputField value="{!cse.Profile_s_Affected__c}"/>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock title="Description Information" >
<apex:pageBlockSection >
    <apex:inputField value="{!cse.Subject}"/>
    <apex:inputField value="{!cse.Driver__c}"/>
    <apex:inputField value="{!cse.Benefit_Of_Change__c}"/>
    <apex:inputField value="{!cse.Reason_For_Change__c}"/>
    <apex:inputField value="{!cse.Description}"/>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock title="Deadlines and Project Status" >
<apex:pageBlockSection >
    <apex:inputField value="{!cse.Target_Deadline__c}"/>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock title="Requesting Department Information" >
<apex:pageBlockSection >
    <apex:inputField value="{!cse.Sponsoring_Department_s__c}"/>
    <apex:inputField value="{!cse.Sponsoring_Dept_GL_Code__c}"/>
    <apex:commandButton value="Submit Change Request" action="{!Save}"/>
</apex:pageBlockSection>
</apex:pageBlock>

</apex:form>
</apex:page>
Apex Class 

public class CaseController{
public Case cse{get;set;}

    public CaseController(ApexPages.StandardController controller) 
    {
        cse=new Case();
    }
    
    
public pagereference Save()
    {
        insert cse;
        PageReference pg=Page.<PageName where you need to redirect>;
        pg.setredirect(true);
        return pg;
    }
}

If this helps,please mark it as best answer to help others.

All Answers

Vinit_KumarVinit_Kumar
Hi Shawn,

Try below code :-

VF page 
<apex:page standardController="Case" extensions="cseController">
<img src="{!$resource.AVISPL_Logo2}"></img>
<apex:pageBlock >
<apex:pageBlockSection title="Hello, Thank You For Your Project Request !" columns="1" showHeader="True" collapsible="False">
</apex:pageBlockSection>
</apex:pageBlock>
<apex:form >
<apex:pageBlock tabStyle="cse" title="Impact" >
<apex:pageBlockSection >
    <apex:inputField value="{!cse.Number_of_Users_Affected__c}"/>
    <apex:inputField value="{!cse.Area_s_Affected__c}"/>
    <apex:inputField value="{!cse.Functionality_Affected__c}"/>
    <apex:inputField value="{!cse.Profile_s_Affected__c}"/>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock title="Description Information" >
<apex:pageBlockSection >
    <apex:inputField value="{!cse.Subject}"/>
    <apex:inputField value="{!cse.Driver__c}"/>
    <apex:inputField value="{!cse.Benefit_Of_Change__c}"/>
    <apex:inputField value="{!cse.Reason_For_Change__c}"/>
    <apex:inputField value="{!cse.Description}"/>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock title="Deadlines and Project Status" >
<apex:pageBlockSection >
    <apex:inputField value="{!cse.Target_Deadline__c}"/>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock title="Requesting Department Information" >
<apex:pageBlockSection >
    <apex:inputField value="{!cse.Sponsoring_Department_s__c}"/>
    <apex:inputField value="{!cse.Sponsoring_Dept_GL_Code__c}"/>
    <apex:commandButton value="Submit Change Request" action="{!Save}"/>
</apex:pageBlockSection>
</apex:pageBlock>

</apex:form>
</apex:page>
Apex Class 

public class CaseController{
public Case cse{get;set;}

    public CaseController(ApexPages.StandardController controller) 
    {
        cse=new Case();
    }
    
    
public pagereference Save()
    {
        insert cse;
        PageReference pg=Page.<PageName where you need to redirect>;
        pg.setredirect(true);
        return pg;
    }
}

If this helps,please mark it as best answer to help others.

This was selected as the best answer
Shawn ReichnerShawn Reichner
Thank you so much!  That worked like a charm, now if I coudl get the newly created case number to populate on the redirected VF page I woudl be complete
Vinit_KumarVinit_Kumar
You need the Case number or Case id which was generated ??
Shawn ReichnerShawn Reichner
Yes, I would like ot have the Case Number that was just created when saved displayed on the new VF page so the user can copy teh case number down to reference later if needed.  Hope that makes sense...
Vinit_KumarVinit_Kumar
You can add a Query to get the Case number.so,your query should be something like below :-

Case c = [select Casenumber from Case where id=:cse.id];
system.debug('#######' + c.Casenumber )'

Put this line after line 13.
Shawn ReichnerShawn Reichner
Vinit, Thank you for your help once again, however, I am getting this error when adding the above code to bring back the case number that was just created.  Error Error: Compile Error: line breaks not allowed in string literals at line 15 column -1

Here is the complete code:

public class CaseController{
public Case cse{get;set;}

    public CaseController(ApexPages.StandardController controller)
    {
        cse=new Case();
    }
   
   
public pagereference Save()
    {
        insert cse;
        PageReference pg=Page.Change_Project_Thank_You;
        Case c = [select Casenumber from Case where id=:cse.id];
        system.debug('#######' + c.Casenumber )'
        pg.setredirect(false);
        return pg;
    }
}
Shawn ReichnerShawn Reichner
Vinit, also noticed another error that is happening now that I added the Apex Class for the standard case controller entention.....  No fields are being populated on a case form now from the submission of the VF page.  They used to populate on the form before we added the class.  Do you have any hints on that one?  If not I will have to not add the extention and will have to find another way to redirect the page. Thank you
Vinit_KumarVinit_Kumar
Shawn change your code from :-

public pagereference Save()
    {
        insert cse;
        PageReference pg=Page.Change_Project_Thank_You;
        Case c = [select Casenumber from Case where id=:cse.id];
        system.debug('#######' + c.Casenumber )'
        pg.setredirect(false);
        return pg;
    }
}

to

public pagereference Save()
    {
        insert cse;
        PageReference pg=Page.Change_Project_Thank_You;
        Case c = [select Casenumber from Case where id=:cse.id];
        system.debug('#######' + c.Casenumber );
        pg.setredirect(false);
        return pg;
    }
}
Shawn ReichnerShawn Reichner
Vinit, I have changed the code, and I still have all of the same issues as listed above.  I thank you for your attempt, however the fields on the case record do not fill out from the submission of the VF page with the extension.......if I remove the extension from the code, the fields will populate on the case form when submitted, and also the case number that has been created is still not populating on the redirected VF page either.  

Again thank you for your help, is there anythign else we can try?

Shawn
Vinit_KumarVinit_Kumar
Shawn,

this should work.Can you debug the issue by setting the debug logs on for theu user.