• adnan ahmad 10
  • NEWBIE
  • 20 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 2
    Replies
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 
how to build a text  comparer in lightning component ? how do i acheive this ? Is there any js libraries that I can use in static resources so that I can use in component to get this functionality ? ..Thanks in Advance 
I have two components ,On click of one component event is firing and through that event  component 2 is getting value . Now I dont want to add 2nd component and wanted to be visible when event is fired . Can I achieve this ?
Im maping as map<invoice__c,List<line_item__c>> Now I have to calculate for each invoice sum of quantity(in line item) is greater than 100 ? if its greater then i have to update status in invoice .
Im maping as map<invoice__c,List<line_item__c>> Now I have to calculate for each invoice sum of quantity(in line item) is greater than 100 ? if its greater then i have to update status in invoice .