0

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


<script>
    $Lightning.use("c:CPM_ContainerApp", function() {
      $Lightning.createComponent("c:CPM_CreateAction",{ 
      },
      "lightning",
      function(cmp) { 
          //cmp.set("v.recordId",ApexPages.CurrentPage().getparameters().get('id'));
      }); 
    });
</script>

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">        
</div>  

Lightning Component Helper

RecTypeId : function(cmp, event, helper) { 
        var action = cmp.get("c.getRecTypeId");
        action.setParams({ 
            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");
                createRecordEvent.setParams({
                    "entityApiName": "CPM_Action__c",
                    "recordTypeId":cmp.get("v.recordTypeId"),
                    "defaultFieldValues": {
                            'CPMCase__c' : cmp.get("v.recordId"),
                            'CPM_Business_Unit__c':'AWP-APAC',
                            'CPM_Status__c':'New',
                            'CPM_Priority__c' :'Medium',
                    }                    
                });
            createRecordEvent.fire(); 
                cmp.set("v.helperExecuted", true);
            }else if (state === "INCOMPLETE"){
            }else if (state === "ERROR"){
                var errors = response.getError();
                if(errors){
                    if (errors[0] && errors[0].message) {
                        console.log("Error message: " + 
                                 errors[0].message);
                    }
                }else{
                    console.log("Unknown error");
                }
            }
        });
        $A.enqueueAction(action);
    }
1

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:

$Lightning.createComponent("c:CPM_CreateAction",
    {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.