2

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

2
  • why don't you try this: window.open('/apex/RecordTypeX_VF?' +'retURL=/'+recId'); Commented Mar 7, 2017 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
    Commented Mar 7, 2017 at 8:25

3 Answers 3

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.

1
  • Great that you found an answer. Commented Mar 7, 2017 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

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

To navigate to another url from within a lightening component you should use sforce.one.navigateToURL("Your_Url");

For Salesforce Classic you could still use window.location.href This is the documentation url for refrence https://help.salesforce.com/articleView?id=sf.lex_prepare_vf_window.htm&type=5

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .