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
Jimmy TrinhJimmy Trinh 

My VisualForce Page is not redirecting after save

Hi in my Controller Extension I have a save method that will insert the record and then calls a PageReference method to redirect the page to a thank you page only if the save was successful. I have my code below and and input or assistance will be helpful.
   

    public void saveObject(){
        if(!NAME)
            checkReqName();
        if(!EMAIL)
            ValidateEmail();
        if(!EMPLOYID)
            checkEmpId();
        if(NAME && EMAIL && EMPLOYID){
            myTask.Status__c = 'New';
            insert myTask;
            myTask = null;
            NAME = false;
            EMAIL = false;
            EMPLOYID = false;
            thankYou();
        }
    }
    
    public PageReference thankYou(){
        System.debug('Entered page redirect');
        PageReference thankYouPage = Page.ThankYou;
        thankYouPage.setRedirect(true);
        return thankYouPage;
    }
Best Answer chosen by Jimmy Trinh
Dilip_VDilip_V
Hi Jimmy,

MOdify your method like this.
 
public PageReference saveObject(){
        if(!NAME)
            checkReqName();
        if(!EMAIL)
            ValidateEmail();
        if(!EMPLOYID)
            checkEmpId();
        if(NAME && EMAIL && EMPLOYID){
            myTask.Status__c = 'New';
            insert myTask;
            myTask = null;
            NAME = false;
            EMAIL = false;
            EMPLOYID = false;
            return thankYou();
        }
    }


Let me know if it helps.

Make it as best answer if it helps.

Thanks.