You need to sign in to do that
Don't have an account?

Getting fields from Apex to Aura component
Hi All,
I have an Aura component in which i have a child component i want to pass the value from Apex to this component. how can i do this?
my Aura and Apex controller is given below:-
public class CommEventsController {
@AuraEnabled(cacheable=true)
public static String getZoneId() {
Set<Id> contactIds = new Set<Id>();
Map< Id, User> mapOfContactIdToUser = new Map<Id,User>();
Map<Id, Forum_Members__c> mapOfForumIdToMembers = new Map<Id,Forum_Members__c>();
for( User ur : [ SELECT Id, ContactId
FROM User
WHERE Id =: userinfo.getUserId() ] )
{
if( ur.ContactId != null ){
mapOfContactIdToUser.put( ur.ContactId , ur );
}
}
System.debug('mapOfContactIdToUser'+mapOfContactIdToUser);
for( Forum_Members__c fm : [ SELECT Id, Member__c,Forum__c
FROM Forum_Members__c
WHERE Member__c IN: mapOfContactIdToUser.KeySet() ] )
{
if( fm.Member__c != null ){
mapOfForumIdToMembers.put(fm.Forum__c,fm);
}
}
System.debug('mapOfForumIdToMembers'+mapOfForumIdToMembers);
List<Forum__c> listOfForum = New List<Forum__c>();
listOfForum = [Select AC_Events_Zone__c from Forum__c where Id IN: mapOfForumIdToMembers.keySet()];
String zoneId = listOfForum.Size()>0?listOfForum[0].AC_Events_Zone__c:Null;
System.debug('zoneId'+zoneId);
return zoneId;
}
}
Aura component:-
<aura:component controller="CommEventsController" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
<aura:attribute name="recordId" type="String" />
<aura:attribute name="zoneId" type="String" />
<bre:DatePicker zoneId="{!v.zoneId}" />
</aura:component>
Controller:-
({
myAction : function(component, event, helper) {
var action = component.get("c.getZoneId");
}
})
I am getting the zoneId in Apex controller and i want to pass it to the component. how can i do it ?
Can anyone help?
I have an Aura component in which i have a child component i want to pass the value from Apex to this component. how can i do this?
my Aura and Apex controller is given below:-
public class CommEventsController {
@AuraEnabled(cacheable=true)
public static String getZoneId() {
Set<Id> contactIds = new Set<Id>();
Map< Id, User> mapOfContactIdToUser = new Map<Id,User>();
Map<Id, Forum_Members__c> mapOfForumIdToMembers = new Map<Id,Forum_Members__c>();
for( User ur : [ SELECT Id, ContactId
FROM User
WHERE Id =: userinfo.getUserId() ] )
{
if( ur.ContactId != null ){
mapOfContactIdToUser.put( ur.ContactId , ur );
}
}
System.debug('mapOfContactIdToUser'+mapOfContactIdToUser);
for( Forum_Members__c fm : [ SELECT Id, Member__c,Forum__c
FROM Forum_Members__c
WHERE Member__c IN: mapOfContactIdToUser.KeySet() ] )
{
if( fm.Member__c != null ){
mapOfForumIdToMembers.put(fm.Forum__c,fm);
}
}
System.debug('mapOfForumIdToMembers'+mapOfForumIdToMembers);
List<Forum__c> listOfForum = New List<Forum__c>();
listOfForum = [Select AC_Events_Zone__c from Forum__c where Id IN: mapOfForumIdToMembers.keySet()];
String zoneId = listOfForum.Size()>0?listOfForum[0].AC_Events_Zone__c:Null;
System.debug('zoneId'+zoneId);
return zoneId;
}
}
Aura component:-
<aura:component controller="CommEventsController" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
<aura:attribute name="recordId" type="String" />
<aura:attribute name="zoneId" type="String" />
<bre:DatePicker zoneId="{!v.zoneId}" />
</aura:component>
Controller:-
({
myAction : function(component, event, helper) {
var action = component.get("c.getZoneId");
}
})
I am getting the zoneId in Apex controller and i want to pass it to the component. how can i do it ?
Can anyone help?
Can you please use below to get value from controller to component.
Hope this is helpful!
Regards,
Ranjan