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
adnan ahmad 10adnan ahmad 10 

how to set values dynamically

This is my component------------------------------------------------------------------------------

<aura:component controller ="DynacmicWrap" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    
    <aura:attribute name="fobjectname" type="String" />
    <aura:attribute name="fields" type="Object[]"/>
    <aura:attribute name="fieldValues" type="String" />
    
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/> 
    
    
    <lightning:recordEditForm aura:id="recordViewForm" 
                              recordId="{!v.recordId}"
                              objectApiName="{!v.fobjectname}">
        <aura:iteration items="{! v.fields }" var="field" indexVar="index">
            <lightning:inputField fieldName="{!field.fapiname}" label="{!index}" value="{!field.value}" 
                                  class="slds-p-top_small slds-m-top_medium" onchange="{!c.fieldChange}"  />
        </aura:iteration>
    </lightning:recordEditForm>
    <lightning:button variant="base" label="Save" title="Base action" onclick="{!c.handleClick }"/>
    
</aura:component>

This is controller------------------------------------------------------------------------------------

 doInit : function(component, event, helper) {
        var action= component.get("c.byschema");
        action.setParams({
            'myId':component.get("v.recordId")
        });
        action.setCallback(this,function(response) {
            var state=response.getState();
            if(state==="SUCCESS") {
                var elements = response.getReturnValue();
               // component.set("v.fields", elements);
                component.set("v.fobjectname", elements[0].fobjectname);
                var records = [];
                var objectName = component.get("v.fobjectname");
                for(var i=0;i<elements.length;i=i+1) {
                    var record = {};
                    var source = elements[i];
                    record.fapiname = source.fapiname;
                    record.value= "";
                    records.push(record);
                }
                component.set("v.fields", records);
            }
        });
        $A.enqueueAction(action);
    },
    
    handleClick : function(component) {
        var fields = component.get("v.fields");
    },
    
    fieldChange : function(component, event, helper) {
        var indexvar = event.getSource().get("v.label");
        var item = component.get("v.fields.[indexvar]");
  items.value = event.getParam("value");
        component.set("v.fields.[indexvar]", item);
    }
})

This is Apex controller---------------------------------------------------------------------------------------------

public class DynacmicWrap {
    @AuraEnabled
    public static list<objectwrapper> byschema(id myId){
        
        Map<string,string> mymap = new map<string,string>();
        String sObjName = myId.getsObjectType().getDescribe().getName();
        Map<String, Schema.SObjectType> global_describe = Schema.getGlobalDescribe();
        Map<String, Schema.SObjectField> object_fields_map = global_describe.get(sObjName).getDescribe().fields.getMap();
        list<string> fieldsapiname= new list<string>();
        list<string> fieldsname = new list<string>();
        list<string> newlist = new list<string>();
        
        list<Schema.DisplayType> types=new list<Schema.DisplayType>();
        
        string apiString;
        string a;
        String nameString;
        Schema.DisplayType typeString;
        
        for (String fieldName: object_fields_map.keySet()) {
            if(object_fields_map.get(fieldName).getDescribe().getName()=='Name' 
                || object_fields_map.get(fieldName).getDescribe().getName()=='Email'
               /* && object_fields_map.get(fieldName).getDescribe().getName()=='Phone' 
                && object_fields_map.get(fieldName).getDescribe().getName()=='Department'
                && object_fields_map.get(fieldName).getDescribe().getName()=='Gender__c'*/) {
                    String apiName = object_fields_map.get(fieldName).getDescribe().getName();
                    system.debug('apiName'+apiName);
                    fieldsapiname.add(apiName);
                    a=object_fields_map.get(fieldName).getDescribe().getLabel();
                      fieldsname.add(a);
                } 
            
        } 
        
       /* for(String fieldtype: object_fields_map.keySet())
        {
            Schema.DisplayType fielddataType = object_fields_map.get(fieldtype).getDescribe().getType();
            types.add(fielddataType);
        }*/
        newlist.add(sObjName);
        list<objectwrapper> wrapList = new list<objectwrapper>();
        for(Integer i=0;i<fieldsname.size();i++){
            objectwrapper wrap=new objectwrapper();
            wrap.fname=fieldsname[i];
            wrap.fapiname=fieldsapiname[i];
           // wrap.fdatatype= types[i];
            wrap.fobjectname=sObjName;
            wrapList.add(wrap);
            system.debug('wrap test'+wrap);
        }
        
        system.debug('wrapList'+wrapList);
        return wrapList;    
    }
    
    public class objectwrapper
    {
        @AuraEnabled
        public string fobjectname
        {
            get;
            set;
        }
        
        @AuraEnabled
        public string fname
        {
            get;
            set;
        }
        @AuraEnabled
        public string fapiname
        {
            get;
            set;
        }
       /* @AuraEnabled
        public Schema.DisplayType fdatatype
        {
            get;
            set;
        }*/
        public objectwrapper(String fobject,String f,String fapi/*Schema.DisplayType fdata*/)
        {
            this.fobjectname=fobject;
            this.fname=f;
            this.fapiname=fapi;
           // this.fdatatype=fdata;
        }
        
        public objectwrapper() {
            
        }
    }
    
}



What I'm no getting is How to iterate to get those input values with corresponding apiname on calling of  Onchange function and how to set to a object type attribute to save it ?
can someone please help me.
Thanks