I have created Custom Button on Case Object using VF Page which contains Lightning Component Inside it. Now I am not able to Pass Current Case ID to the Lightning component which is blocking my development. Can anyone help? Thanks in advance for your support!! :)

VF Page Code

    $Lightning.use("c:CPM_ContainerApp", function() {
      function(cmp) { 

Lightning App

Lightning Component

<aura:attribute name="recordTypeId" type="String" access="public"/>
<aura:attribute name="recordId" type="String" access="public"/>
<aura:attribute name="helperExecuted" type="boolean" default="false"/>

<aura:handler name="init" value="{!this}" action="{!c.doInit}" access="public"/>

<div class="slds">        

Lightning Component Helper

RecTypeId : function(cmp, event, helper) { 
        var action = cmp.get("c.getRecTypeId");
            CaseId : cmp.get("v.recordId") 
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS"){
                cmp.set("v.recordTypeId", response.getReturnValue());
                var createRecordEvent = $A.get("e.force:createRecord");
                    "entityApiName": "CPM_Action__c",
                    "defaultFieldValues": {
                            'CPMCase__c' : cmp.get("v.recordId"),
                            'CPM_Priority__c' :'Medium',
                cmp.set("v.helperExecuted", true);
            }else if (state === "INCOMPLETE"){
            }else if (state === "ERROR"){
                var errors = response.getError();
                    if (errors[0] && errors[0].message) {
                        console.log("Error message: " + 
                    console.log("Unknown error");

You are not passing the recordId from your VF page currently.

The empty braces {} in your following snippet represents which attributes you need to pass to your component and that currently you are not passing anything.

$Lightning.createComponent("c:CPM_CreateAction",{}, ....

You will need to change it to something as below for the component to receive arguments from the VF page:

    {recordId: ApexPages.CurrentPage().getparameters().get('id'), <any other params>}, ....
| improve this answer | |

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.