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
Dippan PatelDippan Patel 

Custom "Save and New" redirection not working Consecutive times

Hi All, 

I have a custom visualforce page and custom controller for entering a record. 

When I click on Save and New button, it works fine the first time but I again fill out the record details and click on the Save and New button, it goes in infinte loop and doesn't redirect to new record page. The record gets saved though. Just not redirected. 

P.S. Classic works fine, The visualforce page uses lightning style sheets in Lightning mode. The issue is in Lightning. 

Below is my code 
<apex:form >

<apex:actionfunction name="action_onSaveAndNew" action="{!onSaveAndNew}"  />



public virtual PageReference onSaveAndNew2(){

				//save record
				String s = '/' + ('' + object.subString(0, 3) + '/e?';
				System.debug(loggingLevel.error, 'String s:    ' + s);
				ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.Info, s));
				PageReference page = new PageReference(s);
				return page;

Any idea why it is not redirecting the second time? 

Thank you.  
SwethaSwetha (Salesforce Developers) 
HI Dippan,
Do you see any error message in logs?
Dippan PatelDippan Patel
Hi Swetha,

No. there is no error in logs. Infact everthing seems to run perfectly fine before this call :

PageReference page = new PageReference(s);
return page;

Thank you.