VF Page:

<apex:page standardController="Opportunity" extensions="P2EcRequestType" lightningStylesheets="true" standardStylesheets="false" >
<apex:slds />
<apex:includeLightning />
<div id="lightning" />
function callApex(){
function lightning(){
    $Lightning.use("c:liu_NewRFIOnOpportunityApp", function() {
                                   { recordId : '{!Opportunity.id}' },
                                   function(cmp) {

<apex:sectionHeader title="Case" subtitle="RFI Type"/>

 body .bEditBlock .pbBottomButtons>table { padding-left : 227px; }
.bPageBlock.bEditBlock .pbBody .data2Col { padding-left : 650px;}
 .apexp .bPageBlock .pbBottomButtons .btn { margin-right : 40px; } 
<apex:form id="form">
    <apex:actionFunction name='callApexMethod' action="{!Submit}" oncomplete="lightning();" />
    <apex:pageMessages ></apex:pageMessages> 
    <apex:pageBlock Title="Choose RFI Type and SubType" tabstyle="CostShare__c"> 
        <apex:pageBlockSection id="RFITypeSec">
            <apex:inputField value="{!RFICase.RFI_Type__c}"/>
            <apex:inputField value="{!RFICase.RFI_SubType__c}"/>

        <apex:pageBlockButtons location="bottom" html-align="center">
            <apex:commandButton styleClass="slds-button slds-button_neutral" value="Submit" onclick="lightning(); return false;" rerender="form"/>   
            <apex:commandButton styleClass="slds-button slds-button_neutral" value="Cancel" action="{!cancel}"/>


<aura:component controller="P2EcNewRFIonOpportunity" implements="lightning:actionOverride,force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickActionWithoutHeader,force:hasSObjectName" access="global">

<aura:attribute name="recordId" type="Id" />
<aura:attribute name="access" type="string" />
<aura:attribute name="anlasis" type="string" />
<aura:attribute name="review" type="string" />
<aura:attribute name="Actual" type="string" />

<aura:attribute name="NewRFI" type="Case" default="{'sobjectType':'Case'}"/>
<aura:handler name="init" action="{!c.doInit}" value="{!this}"/>


doInit : function(component,event,helper){
    var recordId = component.get("v.recordId");        
    var action = component.get("c.newrfiopportunity"); 
    action.setCallback(this, function(response) {
        if (response.getState() ===  "SUCCESS") {  
            if(response.getReturnValue() != null ) {
                 var storeResponse = response.getReturnValue();
            component.set("v.NewRFI", storeResponse);                 


recordCreation : function(component,cse) {

    var windowHash = window.location.hash;
    var evt = $A.get("e.force:createRecord");
        'defaultFieldValues': {


Apex controller of Component:

public class P2EcNewRFIonOpportunity {

public static Case newrfiopportunity(Id recordId){

    Opportunity Opprty = new Opportunity();     
    List<RecordType> lstRecType = new List<RecordType>();
    Map<String,Id> mapRecType = new Map<String,Id>();
    Case cse = new Case();

    String sObjectparentId = '';
    String CaseRecType = '';
    sObjectparentId = recordId;

    lstRecType = [SELECT Id,DeveloperName FROM RecordType WHERE sobjecttype = 'Case'];
        for(RecordType rec: lstRecType){
            Opprty = [select id, AccountId from opportunity where id=:sObjectparentId];
       CaseRecType = 'RFI_Geo'; 
       cse.Related_Opportunity__c= Opprty.id;
       cse.AccountId = Opprty.AccountId;
       cse.RecordTypeId =mapRecType.get(CaseRecType); 

    return cse;

public static Case saveCase(Case css){
    upsert css;
    return css;


In VF Page I am calling above lighting component when I click on the Submit Button. I have an input field(Picklist -access analysis review actual) on the same page.

the input field is RFICase.RFI_Type__c

Now I need to pass the Opportunity id to the lightning component and Picklist values also. Based on picklist values I need to populate the standard record creation page of the object with different record types from the lighting component.

I am not able to pass parameters at { recordId : '{!Opportunity.id}' }, in function lightning(){

Can anyone please help me how to pass values from VF Page to lightning component?


This page has an error. You might just need to refresh it. Error in 
$A.getCallback() [Cannot read property 'setParams' of undefined] 
Callback failed: apex://P2EcNewRFIonOpportunity/ACTION$newrfiopportunity 
Failing descriptor: {c:liu_NewRFIOnOpportunity}

enter image description here

  • Your issue seems to be on this line action.setParams({"recordId":recordId}); in doInit function. Do you have the method newrfiopportunity in your Apex controller? Also when you say you are not able to pass the value, how have you verified that? Try putting a console.log in doInit function. Can you also post the Apex method which is being called in the JS?
    – Jayant Das
    Feb 12, 2019 at 20:13
  • Yeah, Jayant I have added console and saw that record is passing. but from the helper console.log('evt%%%%'+evt); is returned undefined. May I know what is the reason. Updated code with the helper.
    – chris
    Feb 12, 2019 at 20:32
  • Didn't follow this. Your console log statements in comments vs. the post are different. Are you able to get component.get("v.recordId") printed in your JS?
    – Jayant Das
    Feb 12, 2019 at 20:34
  • Yeah, Jayant you are correct I got the Id in JS. But can you please help me with that error?. Updated log picture
    – chris
    Feb 12, 2019 at 20:38
  • Can you post your Apex controller? It seems you don't have either the method or right arguments in there. Also I couldn't see where you have the log printing the evt, that piece of code seem missing in current post.
    – Jayant Das
    Feb 12, 2019 at 20:39

2 Answers 2


I recommend to use the new Lightning Message Service (Beta as of Spring '20) as it's specially designed for that purpose.


Consider reading Communicating between Lightning Components and Visualforce Pages, to receive the messages in your Lightning Component you need to add listener for a message event.

When your lightning component initilizes, you will have to add an event listener, as per your Visualforce page, you will have to register a method, fire it with the appropriate parameters and origin in context.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .