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
Harsha ShriHarsha Shri 

Redirect issue in VF Page commandbutton

HI All,
I am having redirect issue in VF page. When I am using reRender and rendered together in commanad button I am getting this issue. If I am not using rerender in command button, It is redirecting to the path what I mentioned in pagereference methond.
This is my code.
public class SaveRecords{
 public PageReference saveToCollege() {
    
        Boolean saved = false;
        saved = Class2.saveCollegeData(WrapperData.result,collegeId);
        if(saved)
        {
            PageReference pg=new PageReference('/'+collegeId );
            return pg;
        }
        
    } 
	}
	
	<apex:page standardcontroller="College__c" controller="SaveRecords">
	<apex:form>
	  <apex:pageBlock id="mySelectedPB1">
	  
			some code
	  </apex:pageBlock>
	 <apex:commandButton action="{!saveToCollege}" value="Link to College" rerender="mySelectedPB1" rendered="{!if(WrapperData.result != null,true,false)}"/>
	</apex:form>
	</apex:page>



Please help me how to resolve this issue.

Thanks in Advance
Saroja MuruganSaroja Murugan
Hi Harsha,

Please change the code as per below.

Page:
 <apex:commandButton action="{!saveToCollege}" value="Link to College" rerender="mySelectedPB1" rendered="{!shouldIRender}"/>

Class
 public boolean getshouldIRender(){

        if(WrapperData.result != null)
            saved = true;
        else
            saved = false;

        return shouldIRender;


    }

For more information please refer the below link
https://salesforce.stackexchange.com/questions/169627/rendering-and-rerendering-a-command-button-after-submitting-a-record

Thanks,
Saroja
Sweet Potato Tec
Harsha ShriHarsha Shri

Hi Saroja,

Thanks you very much for your support
Here my problem is, after command button it is not redirecting to record home page which I mentioned in pagereference method. record is saving but it is not redirecting to the path what I mentioned in pagereference method.
Can you please help me

Regards,
Harsha

Saroja MuruganSaroja Murugan
Hi Harsha,

public PageReference save() {
  
       PageReference pg=new PageReference('/'+college__c.Id );
     return pg;
}

Hope this helps!

Thanks,
Saroja
 
Harsha ShriHarsha Shri
Hi Saroja,
Thank you very much for your continuious support.
I tried it. but it is not working