You need to sign in to do that
Don't have an account?
SFDC pv
Can someone please help me on how to call a child component from Parent component
If i click on the "New Button" i need to call the child component which is a pop up window.
This is my component i will place the below icon on my case page
Parent Component : -
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" controller ="Test_CreateXXController" access="global" >
<aura:attribute name="isOpen" type="boolean" default="false"/>
<aura:attribute name="recordId" type="String" />
<c:Testcomponent aura:id="child"/>
<!-- <aura:handler name="init" value="{!this}" action="{!c.doInit}"/> -->
<div onclick="{!c.doInit}">
<a class="Fontcolor" href=""><lightning:card iconName="utility:info" title="New Button" /></a>
</div>
<!-- </div> -->
</aura:component>
Controller:-
({
doInit: function(component, event, helper) {
console.log('intosearch');
//helper.Navigate(component, event, helper);
var testComponent = component.find('child');
console.log('childcomponent');
testComponent.getchildMethod();
}
})
Child component :-
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
<aura:method name="getchildMethod" action="{!c.doAction}"/>
<aura:attribute name="isOpen" type="boolean" default="True"/>
This is not working. Please help me out.
This is my component i will place the below icon on my case page
Parent Component : -
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" controller ="Test_CreateXXController" access="global" >
<aura:attribute name="isOpen" type="boolean" default="false"/>
<aura:attribute name="recordId" type="String" />
<c:Testcomponent aura:id="child"/>
<!-- <aura:handler name="init" value="{!this}" action="{!c.doInit}"/> -->
<div onclick="{!c.doInit}">
<a class="Fontcolor" href=""><lightning:card iconName="utility:info" title="New Button" /></a>
</div>
<!-- </div> -->
</aura:component>
Controller:-
({
doInit: function(component, event, helper) {
console.log('intosearch');
//helper.Navigate(component, event, helper);
var testComponent = component.find('child');
console.log('childcomponent');
testComponent.getchildMethod();
}
})
Child component :-
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
<aura:method name="getchildMethod" action="{!c.doAction}"/>
<aura:attribute name="isOpen" type="boolean" default="True"/>
This is not working. Please help me out.
I trust you are doing very well.
Below is the sample code to create the contact using aura method which I have tested in my org and it is working fine. Kindly modify the code as per your requirement.Parent Component: LightningMethodParent
Parent Controller: LightningMethodParent Controller
Child Component: LightningMethodChild
Child Controller: LightningMethodChildController
Note: When you try to launch the component via app in the developer console, standard events (createRecord, showToast, navigateToSobject, etc) will be undefined.
Therefore launch LightningMethodParent component in LEX via app builder or create a lightning tab or lightning quick action or drag to the detail page to check how it works.
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in future.
Thanks and Regards,
Khan Anas
You need to change the controller method name from doInit to Search. And also, change the helper method name.
Controller:
Helper:
I hope it helps you.
Kindly mark this as solved if the information was helpful.
Thanks and Regards,
Khan Anas
intosearchHelper
Test_ModalSearchComponent.js:16 actionSecureAction: [object Object]{ key: {"namespace":"c"} }
Test_ModalSearchComponent.js:23 ####returnvalueERROR
Test_ModalSearchComponent.js:25 ####parentIdnull
Test_ModalSearchComponent.js:14 intosearchHelper
Test_ModalSearchComponent.js:16 actionSecureAction: [object Object]{ key: {"namespace":"c"} }
Test_ModalSearchComponent.js:23 ####returnvalueERROR
Test_ModalSearchComponent.js:25 ####parentIdnull
Test_ModalSearchComponent:-
<aura:component controller ="Test_xxController" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
<div style="display:inline-block;margin-right:10px" onclick="{!c.Search}">
<lightning:icon iconName="utility:search" size="small" >
</lightning:icon>
Controller:-
({
Search : function(component, event, helper) {
var action = component.get("c.invokeWebService");
console.log('action');
action.setParams({
"CaseId" : component.get("v.recordId")
});
action.setCallback(this, function(response) {
var state = response.getState();
console.log('####returnvalue'+state);
var parentId = component.get('v.recordId');
console.log('####parentId'+response.getReturnValue());
if (state == "SUCCESS") {
var output = response.getReturnValue();
component.set("v.response", output);
console.log(output);
}
});
$A.enqueueAction(action);
},
})
Apex controller:-
global class Test_xxController {
@AuraEnabled
@future(callout=true)
Public static void invokeWebService(String CaseId) {
Map <String,xx_Information__c > FFMap = new Map <String,xx_Information__c> ();
Map<String, Integer> monthAndMonthNumberMap = new Map<String, Integer>();
monthAndMonthNumberMap.put('Jan', 1);
monthAndMonthNumberMap.put('Feb', 2);
monthAndMonthNumberMap.put('Mar', 3);
monthAndMonthNumberMap.put('Apr', 4);
monthAndMonthNumberMap.put('May', 5);
monthAndMonthNumberMap.put('Jun', 6);
monthAndMonthNumberMap.put('Jul', 7);
monthAndMonthNumberMap.put('Aug', 8);
monthAndMonthNumberMap.put('Sep', 9);
monthAndMonthNumberMap.put('Oct', 10);
monthAndMonthNumberMap.put('Nov', 11);
monthAndMonthNumberMap.put('Dec', 12);
List<Case> Caslist= [SELECT Id,AccountID,xx_Number__c FROM Case WHERE ID =:CaseId ];
List<xx_Information__c> listofFF = new List<xx_Information__c>();
List<xx_Information__c> DFFlist= new list<xx_Information__c>([SELECT xx_Number__c FROM xx_Information__c WHERE Case__c =:CaseId ]);
Set<String> loffinstr = new Set<String>();
Set<String> Dloffinstr = new Set<String>();
Set<String> Nloffinstr = new Set<String>();
Boolean isDuplicate;
for(xx_Information__c finfo : DFFlist ){
loffinstr.add(finfo.xx_Number__c);
Dloffinstr.add(finfo.xx_Number__c);
}
Case Cas= [SELECT Id,AccountID,xx_Number__c FROM Case WHERE ID =:CaseId ];
system.debug('***Case-FF***'+Cas);
for (String num : Cas.xx_Number__c.split(',') )
{
system.debug('Numbers'+num);
if (Nloffinstr.Contains(num)) {
// Isduplicate = true;
}
else {
Nloffinstr.add(num);
}
if(num!='' && !loffinstr.contains(num)){
system.debug('insideloop'+num);
loffinstr.add(num);
xx_ResponseWrapper xxResponse = xx_InvokeAPI.invokexxAPI(num);
system.debug('$$$xxResponse$$$'+xxResponse);
if(xxResponse != Null){
xx_Information__c ff = new xx_Information__c();
ff.Name = xxResponse.firstName+' '+xxResponse.lastName;
ff.xx_Email__c = xxResponse.email;
ff.xx_Number__c = num;
ff.Case__c = Cas.ID;
ff.Account__c = Cas.AccountId;
for(xx_xxResponseWrapper.programDetails program: xxResponse.programDetails){
if(program.ffExpireDate!=null){
String myDateStr = program.ffExpireDate;
System.debug('$$$ mydateStr: '+ myDateStr);
List<String> myDateList = myDateStr.split('-');
Integer yearVal = Integer.valueOf(myDateList.get(2));
Integer monthVal = monthAndMonthNumberMap.get(myDateList.get(1));
Integer dayVal = Integer.valueOf(myDateList.get(0));
date mydate = date.newinstance(yearVal,monthVal,dayVal);
ff.Freq_Flyer_Expiry_Date__c = mydate;
ff.Current_Tier__c = program.tierName;
}
}
ff.Request_Type__c = '';
ff.Upgrade_Tier_Requested__c = '';
listofFF.add(ff);
}
}
}
if(listofFF.size()>0) {
insert listofFF;
system.debug('Insertion'+listofFF);
}
}
}