+ Start a Discussion
Darshit Pathak 3Darshit Pathak 3 

Why page is not getting redirected to the detail Page of inserted record even if Id is available?

A command button on VF page that should calls one method,insert the record and redirect to that record.

This is my code:
System.debug('@@@BatchVar Id: '+batchVar.id);
                     return new PageReference('/'+batchVar.id);

It redirects to the same VF page only.
but in debug logs I can see the record Id in debug statement and if I copy that Id and append in browser's URL, the record is opening .
That means method is called and record is inserted properly.
But redirection is not happening properly.
pradeep kumar yadavpradeep kumar yadav
Try this
PageReference pageRef = new PageReference('/'+batchVar.id);
pageRef.setRedirect(true);
return pageRef;

 
Darshit Pathak 3Darshit Pathak 3

Still not working.Showing as before only. It shows blank page and address bar shows Url of current VF Page.

 

pradeep kumar yadavpradeep kumar yadav
String batchID = batchVar.id;
PageReference pageRef = new PageReference('/'+batchID);
pageRef.setRedirect(true);
return pageRef;

 
pradeep kumar yadavpradeep kumar yadav
If it doesn't work then please show me all code and I will find error.
Darshit Pathak 3Darshit Pathak 3

Yeah it's still not working.
1 point I want to bring to your notice that I've used SLDS for my VF page designing.

So does it affect ?

pradeep kumar yadavpradeep kumar yadav
No, SLDS styling doesn't affect, and one I want to tell that if you used reRender on commandButton then it should not work.