[SalesForce] Lightning URL hack issue with prepopulating fields on Page Load

I have Visualforce Page which redirects to standard accounts edit page with prepoulated value for record Type. The record type is getting populated using URL hack. But since URL hacks dont work in lightning experience this functionality is not working and the record type is not populated.

Is there any other workaround to redirect to a standard page with pre-poulated values in Lightning?

Best Answer

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];
        }     
    }

}
Related Topic