function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Badal ShindeBadal Shinde 

Pass list attribute from lightning component to apex controller and fetch record data dynamically

I wanted to try pass the object Name and thier related query by using design attribute and show the records on app page but I have no idea how to do this. please help me.

User-added image

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" > <aura:attribute name="objectName" type="String" /> <aura:attribute name="Query" type="String" /> <aura:handler name="init" action="{!c.doInit}" value="{!this}"/> <lightning:card> test </lightning:card> </aura:component>

<design:component> <design:attribute name="objectName" Label="Object Name"/> <design:attribute name="Query" Label="Query"/> </design:component>

 
SwethaSwetha (Salesforce Developers) 
HI Badal,
I see you also posted on https://salesforce.stackexchange.com/questions/392104/pass-list-attribute-from-lightning-component-to-apex-controller-and-fetch-record

Copying related code from above post:
You just need some Apex code to complete the project:
public class MyController {
  @AuraEnabled public static sObject[] getRecords(String query) {
    return Database.query(query);
  }
}

And in your component markup:
controller="MyController"

And in your doInit method:
doInit: function(component, event, helper) {
  let action = component.get("c.getRecords");
  let query = component.get("v.Query");
  action.setParams({ query });
  action.setCallback(this, function(response) { 
    // Handle response here
  });
  $A.enqueueAction(action);
},

Please consider marking the answer as best to close the thread so others can find it helpful too. Thank you