Pritam, you can try to identify if you are in lightning or not by the code below and then redirect the user to the appropriate experience.
I don't think that is the best solution in terms of UX, but is a way.
function isLightningExperienceOrSalesforce1() {
return((typeof sforce != 'undefined') && sforce && (!!sforce.one));
}
First you create a lightning Application name myFirstApp which retrieve data from the url.
if your URl is like this /c/ChooseCampaignApp.app?AccountId=001P000000eM5z7&ContactId=003P000000hlONG
Then the attribute name must be same as the the Url which contains the values
myFirstApp.app
<aura:application>
<aura:attribute name=”AccountId” type=”String”/>
Value in AccountId Attribute: {!v.AccountId}
<c:AccountByID accGetID=”{!v.AccountId}”/>
Create a component Name: AccountFormByID, adding a server-side controller, AccountFormByIDController, with an attribute: accGetID
<aura:component controller=”AccountFormByIDController” >
<aura:attribute name=”accGetID” type=”String”/>
<aura:attribute name=”ac” type=”Account”/>
<aura:handler name=”init” value=”{!this}” action=”{!c.doInitAction}” />
<ui:inputText label=”Account Name” value=”{!v.ac.Name}”/>
<ui:inputText label=”Type” value=”{!v.ac.Type}”/>
<ui:inputText label=”Industry” value=”{!v.ac.Industry}”/>
</aura:component>
Client-side Controller:
({
doInitAction : function(component, event, helper) {
var action = component.get(“c.find_AccById”);
action.setParams({ “get_accountid”: component.get(“v.accGetID”) });
action.setCallback( this, function(response) {
var state = response.getState();
if (state === “SUCCESS”) {
component.set(“v.ac”, response.getReturnValue());
console.log(response.getReturnValue());
}
});
$A.enqueueAction(action);
},
})
Server side Controller:-
public class AccountFormByIDController {
@AuraEnabled
public static Account find_AccById(Id get_accountid) {
if(get_accountid != null ) {
return [SELECT Id, Name, Type, Industry from Account where ID = :get_accountid];
}
else{
return [SELECT ID, Name, Type, Industry from Account LIMIT 1];
}
}
}
Best Answer
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.
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: