You need to sign in to do that
Don't have an account?
Jayant Kumar Jaiswal
Error in calling Lightning Component from VisualForce Page
Hi,
I have to simply call a lightning component from a VisualForce Page. Later this VF page is configured as a list button in Opportunity.
VF Page::
Component:
JS Controller:
Apex Controller:
If I run the LC from actions, it is working.
Error: $A.getCallback() [Unable to get property 'setParams' of undefined or null reference] Callback failed: apex://RelatedListNewRecordPOCController/ACTION$getParameters
Can anyone please help. As per requirement I have to configure it in list button and I'm not able to dibug this.
I have to simply call a lightning component from a VisualForce Page. Later this VF page is configured as a list button in Opportunity.
VF Page::
<apex:page standardController="Opportunity" recordSetVar="opp" tabStyle="Opportunity"> <apex:includeLightning /> <script> // var recordid = "{!$CurrentPage.parameters.id}"; $Lightning.use("c:LightningOutContainerApp", function() { $Lightning.createComponent("c:RelatedListNewRecordPOC", { oppRecordId : "0069000000x6KWSAA2" }, "RelatedListNewRecordPOCContainer", function(cmp) { console.log('Component created, do something cool here'); }); }); </script> </apex:page>Lightning App:
<aura:application access="GLOBAL" extends="ltng:outApp"> <aura:dependency resource="c:RelatedListNewRecordPOC"/> </aura:application>
Component:
<aura:component controller="RelatedListNewRecordPOCController" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,forceCommunity:availableForAllPageTypes" access="global" > <aura:attribute name="oppRecordId" type="String"/> <aura:handler name="init" value="{!this}" action="{!c.doInit}"/> </aura:component>
JS Controller:
({ doInit: function(component, event, helper) { var myRecordId = "0069000000x6KWSAA2";//component.get("v.recordId"); var getParameters = component.get('c.getParameters'); getParameters.setParams({ "myRecordId": myRecordId }); getParameters.setCallback(this, function(response) { var state = response.getState(); if (state === "SUCCESS") { var Opportunity = response.getReturnValue(); var createAcountContactEvent = $A.get("e.force:createRecord"); createAcountContactEvent.setParams({ "entityApiName": "Opportunity", "RecordTypeId": Opportunity.RecordTypeId, "defaultFieldValues": { 'AccountId': Opportunity.AccountId, 'Name': Opportunity.Name, 'StageName':Opportunity.StageName, 'CloseDate':Opportunity.CloseDate } }); createAcountContactEvent.fire(); } else { var closeAction = $A.get("e.force:closeQuickAction"); closeAction.fire(); } }); $A.enqueueAction(getParameters); $A.get("e.force:closeQuickAction").fire(); }, })
Apex Controller:
public class RelatedListNewRecordPOCController { @AuraEnabled public static Opportunity getParameters(Id myRecordId){ return [SELECT Id, AccountId, RecordTypeId, Name, Description, StageName, Amount , TotalOpportunityQuantity, CloseDate, Type, LeadSource, IsClosed FROM Opportunity WHERE Id =: myRecordId ]; } }Here I'm getting an error while calling the getParameters() function from LC only when from VF page which is configured in list button.
If I run the LC from actions, it is working.
Error: $A.getCallback() [Unable to get property 'setParams' of undefined or null reference] Callback failed: apex://RelatedListNewRecordPOCController/ACTION$getParameters
Can anyone please help. As per requirement I have to configure it in list button and I'm not able to dibug this.
you have to replace your apex controller with the following code:
This the error showing in your apex controller.
Error:- No such column 'RecordTypeId' on entity 'Opportunity'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.
public class RelatedListNewRecordPOCController
{
@AuraEnabled
public sattic Opportunity getParameters(Id myRecordId)
{
return [SELECT Id, AccountId, Name, Description, StageName, Amount , TotalOpportunityQuantity, CloseDate, Type, LeadSource, IsClosed FROM Opportunity WHERE Id =: myRecordId ];
}
}