0

We have a visualforce page on opportunity which is redirecting the URL as below

/02i?rlid=RelatedAssetList&id=001800000....

i.e redirect to Asset related list of an accountId mentioned. This is not working in lightning experience as it is an URL hack.

Is there any alternative approach to redirect to related list of account from the same visualforce page without rewriting it in Lightning?

  • 2
    not in accordance with best practices, you will want to use lightning events for the redirection – glls Oct 15 '18 at 19:09
  • Like +1@glls suggested i would suggest leveraging something like lighting quick actions to rewrite and leverage lightning navigation events! – codeyinthecloud Oct 15 '18 at 19:26
1

Is there any alternative approach to redirect to related list of account from the same visualforce page without rewriting it in Lightning?

If there is one thing to retain from all the documentation and blogs on the subject, it is the following while you are at it.

URL hacks were never officially supported

that being said, you will want to actually migrate from unsuported URL hacks to an actual lightning component that leverages Lightning Navigation Events.

Based on what you have posted, the code itself should be pretty trivial and easy to implement in a lightning component. (redirect to a related list page of the current record)

you might want to check the documentation for lightning navigation events:

you will need to use a recordId attribute (for the current record in context)

and in your component, you can easily create a hyperlink or button that references the page where your related list is.

btw, there is a native lightning event to Navigate To Related List towards a related list:

gotoRelatedList : function (component, event, helper) {
  var relatedListEvent = $A.get("e.force:navigateToRelatedList");
  relatedListEvent.setParams({
      "relatedListId": "Cases",
      "parentRecordId": component.get("v.recordId")
  });
  relatedListEvent.fire();
}
0

If you want to stick to the Visualforce page, You still have an option apart from URL hack. i.e using:-

sforce.one.navigateToRelatedList(relatedListId, parentRecordId)

Navigates to a related list for the parentRecordId. For example, to display a related list for an Account object, the parentRecordId is Account.Id. relatedListId is the API name or ID of the related list to display.

Sample Code:-

<apex:page >
    <script type="text/javascript">
        var myUserContext = "{!$User.UIThemeDisplayed}";
        function naviToRelatedList(recordId) {

            if (myUserContext == 'Theme4t' || myUserContext == 'Theme4d') {
                sforce.one.navigateToRelatedList('Contacts', recordId);
            } else {
                window.location.href = '/' + recordId;
            }

            return false;
        }
    </script>
</apex:page>

Note:- sforce.one.navigateToRelatedList it works only in lightning and mobile app, so for the classic, you have to handle separately.

Here,

Theme4d -Lightning Experience
Theme3- Classic
Theme4t- Mobile App

You have to also call the method naviToRelatedList(recordId) in your VF page onclick or oncomplete or whenever you want.

Reference:- Navigation with the sforce.one Object

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.