1

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).

  • why don't you try this: window.open('/apex/RecordTypeX_VF?' +'retURL=/'+recId'); – Rohit Mourya Mar 7 '17 at 6:49
  • Window.open will open a new tab which is not the requirement. the URL should get updated for the same tab. – Rajeev Mar 7 '17 at 8:25
2

The issue is shorted now ,

To update current page URL on navigation to other page, we should use "this.parent" for constructing URL.

Thus, replacing

window.location.href

with

this.parent.location.href

is the answer.

window.location.href will navigate you to the correct page but the URL will persist as the older one only.

  • Great that you found an answer. – Rohit Mourya Mar 7 '17 at 8:38
1

this is incorrect:

window.location.href =  '/apex/RecordTypeX_VF?' 
    +'&retURL=/'+recId ;

you have an & after the ?

Change to

window.location.href =  '/apex/RecordTypeX_VF?retURL=/'+recId ;

Also, you should look into URLFOR instead for constructing the url

  • Thank you for the correction. that miss was due to removal of other parameters. I have updated the question. – Rajeev Mar 7 '17 at 8:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.