What Am I doing ?
I have this JavaScript list button 'Create Record for RecordType X' on Object B (which is child to Object A) to navigate to the correct VF page "RecordTypeX_VF" with RetUrl of Object B's record's Id , if selected from related list.
Which code does that ?
The JS button code lines responsible doing this are -
var recId = window.location.href.substring(window.location.href.lastIndexOf('/') + 1);
window.location.href = '/apex/RecordTypeX_VF?retURL=/'+recId ;
What is happening ?
The page get redirected to desired VF page but the URL doesn't gets update in the browser, i.e. the same old URL gets shown.
So, what is the problem ?
RecordTypeX_VF fetched the RetUrl from page url and shows different Screens based on the navigation (from tab / related list). Now, that the URL isn't getting updated on navigation to RecordTypeX_VF page, the page does not get the retURl and shows the generic view(how it should look when it is coming from tab).
window.open('/apex/RecordTypeX_VF?' +'retURL=/'+recId');