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
srinadhsrinadh 

Redirect the same page in master page after creation of child??

i have developed One VF Page:

1.How to redirect the Same page after saving the record???
2.How to Implement Save & New Functionality ???

VF Page

<apex:page standardController="Work_Performed__c">
<apex:form >
        <apex:pageBlock title="Work performed">
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save"/>
                 <apex:commandButton action="{!cancel}" value="Cancel"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection title="Work Performed" columns="2" collapsible="true" dir="LTR" id="My">
                <apex:inputField value="{!Work_Performed__c.Note__c}"/>
                <apex:inputField rendered="false" value="{!Work_Performed__c.Case_Number__c}"/>
               
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

HariDineshHariDinesh

Hi,

 

You can't achieve this using standared controller.

You need to use controller extension or Controller for this.

 

Modify your VF code like below  and let's say page name is "saveandnew"

<apex:page standardController="Work_Performed__c" extensions="saveandnewclass">
<apex:form >
        <apex:pageBlock title="Work performed">
            <apex:pageBlockButtons >
                <apex:commandButton action="{!saveandnew}" value="Save"/>
                 <apex:commandButton action="{!cancel}" value="Cancel"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection title="Work Performed" columns="2" collapsible="true" dir="LTR" id="My">
                <apex:inputField value="{!Work_Performed__c.Note__c}"/>
                <apex:inputField rendered="false" value="{!Work_Performed__c.Case_Number__c}"/>
               
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 Create new apex class,the controller code will be

 

public with sharing class saveandnewclass {

     Work_Performed__c wpc;  
    ApexPages.StandardController sController;  
    
    public saveandnewclass(ApexPages.StandardController controller) 
    {
        sController = controller;
        wpc = (Work_Performed__c)controller.getRecord();
    }

public PageReference saveAndNew() {
        
        // Custom Save code here...
        
         sController.save();
         PageReference pageRef = new PageReference('/apex/saveandnew');
         pageRef.setredirect(true);
        return pageRef ;
    }


}

 Try this Code.

your problem will be solved and you will be redirected to same page after saving the record,i.e save and new Functionality.

 

srinadhsrinadh

Hi Hari,

 

Thanks for your response....

It is Redirecting to same page Work performed detail Page.but i want to redirect to Case Detail Page.....

 

HariDineshHariDinesh

Hi,

 

If you want to redirect to detail page, then chage the redirection path.

just change below line you will be redirected to detail page.

 

PageReference pageRef = new PageReference('/'+sController.getrecord().id);

 

Now your code seems like below:

 

public with sharing class saveandnewclass {

     Work_Performed__c wpc;  
    ApexPages.StandardController sController;  
    
    public saveandnewclass(ApexPages.StandardController controller) 
    {
        sController = controller;
        wpc = (Work_Performed__c)controller.getRecord();
    }

public PageReference saveAndNew() {
        
        // Custom Save code here...
        
         sController.save();
         //PageReference pageRef = new PageReference('/apex/saveandnew');
         PageReference pageRef = new PageReference('/'+sController.getrecord().id);
         pageRef.setredirect(true);
        return pageRef ;
    }


}