0

I am trying to replace a URL button used in a list view in Classic to Lightning Compatible. I am trying to open a lightning component through URL that fires the create new page of the object with prepopulated values. The lightning component is like below

Component

<aura:component implements="lightning:isUrlAddressable"  >
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
</aura:component>

Controller

({
 doInit : function(component, event, helper){
   var createRecordEvent = $A.get("e.force:createRecord");
     var record_Id = 'XXXYYYZZZZ';
     var alert = 'Test';

   createRecordEvent.setParams({ 
     "entityApiName": "Inventory__c", 
                       'recordTypeId': record_Id,
    "defaultFieldValues": {
      'alert__c' : alert
    } 
  });
  createRecordEvent.fire(); 
 }
})

I created the URL button and have the URL like /lightning/cmp/c__createInventory where createInventory is the lightning component name, when clicking on the button it navigates to the blue screen nothing is happening no errors / no create new page getting fired. Can anyone please help me here what I am missing.

1

Navigating to a lightning component via a URL button will work in these scenarios:-

Approach 1

You can generate a URL where you pass Base64 encoded object of component definition:-

var compDefinition = {
    componentDef: "c:createInventory",
    attributes: {        
    }
};
// Base64 encode the compDefinition JS object
var encodedCompDef = btoa(JSON.stringify(compDefinition));
console.log('/one/one.app#' + encodedCompDef);

The log prints the following value:- /one/one.app#eyJjb21wb25lbnREZWYiOiJjOmNyZWF0ZUludmVudG9yeSIsImF0dHJpYnV0ZXMiOnt9fQ==

You can then make use of this URL in your URL button.

Approach 2

Create a lightning app page and add your component there. Now simply navigate to lightning app page from the URL button using App Page URL.

/lightning/n/pagename

2
  • in Approach 1, where Should I add the lightning component definition, Is it with the lightning component itself? – user81642 Oct 5 '20 at 12:16
  • you don't need to add component definition, you just need to add the URL generated using component definition in the url button. – sanket kumar Oct 5 '20 at 14:45
0

This seems to be a release issue and actively worked upon. Kindly review Known issue and try workaround mentioned. Also, take a look at URL hacking for lightning.

Thanks,

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.