Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
added 20 characters in body
Source Link
Owen
  • 13
  • 5
component.set('v.AssetsType'AssetsList', {'TypeLabel': 'Asset Type', 'TypeValue': '','TypeId': 'AssetType1', 
                               'AmountLabel': 'Asset Amount', 'AmountValue': '', 'AmountId': 'AssetAmount1'});
    var AssetList =AssetList= cmp.get('v.AssetsType'AssetsList');
    var FactfindId = cmp.get('v.ffRecord.Id');
    var inputAssetListinputAssetListAction = cmp.get("c.inputAssetList");

    inputAssetListinputAssetListAction.setParams({
        "AssetList": AssetList,
        "FactfindId": FactfindId
    });

    inputAssetListinputAssetListAction.setCallback(this, function (response) {
        //store state of response
        var state = response.getState();
        if (state === "SUCCESS") {
            console.log(state);
            if (response.getReturnValue() != null) {
                // if getting any error while update the records , then display a alert msg/
                alert('The following error has occurred. while updating record-->' + response.getReturnValue());
            } else {
                console.log('check it--> update successful');
            }
        }
    });
    $A.enqueueAction(inputAssetListinputAssetListAction);   
public static void inputAssetList(list<String> AssestListAssetList, string FactfindId) {
    
    FactfindMultiples__c[] Assets = new List<FactfindMultiples__c>();
    
    for(Integer i=1;i<AssestListi=1;i<AssetList.size();i++)
    {
        FactfindMultiples__c Asset = new FactfindMultiples__c(Name='Asset' + i, 
                                                              AssetType__c= AssestList[i]AssetList[i].TypeValue);
        Assets.add(Asset);
        
    }
}

I've tried syntax like AssestList[i]AssetList[i].TypeValue but this returns errors.

component.set('v.AssetsType', {'TypeLabel': 'Asset Type', 'TypeValue': '','TypeId': 'AssetType1', 
                               'AmountLabel': 'Asset Amount', 'AmountValue': '', 'AmountId': 'AssetAmount1'});
    var AssetList = cmp.get('v.AssetsType');
    var FactfindId = cmp.get('v.ffRecord.Id');
    var inputAssetList = cmp.get("c.inputAssetList");

    inputAssetList.setParams({
        "AssetList": AssetList,
        "FactfindId": FactfindId
    });

    inputAssetList.setCallback(this, function (response) {
        //store state of response
        var state = response.getState();
        if (state === "SUCCESS") {
            console.log(state);
            if (response.getReturnValue() != null) {
                // if getting any error while update the records , then display a alert msg/
                alert('The following error has occurred. while updating record-->' + response.getReturnValue());
            } else {
                console.log('check it--> update successful');
            }
        }
    });
    $A.enqueueAction(inputAssetList);   
public static void inputAssetList(list<String> AssestList, string FactfindId) {
    
    FactfindMultiples__c[] Assets = new List<FactfindMultiples__c>();
    
    for(Integer i=1;i<AssestList.size();i++)
    {
        FactfindMultiples__c Asset = new FactfindMultiples__c(Name='Asset' + i, 
                                                              AssetType__c= AssestList[i].TypeValue);
        Assets.add(Asset);
        
    }
}

I've tried syntax like AssestList[i].TypeValue but this returns errors.

component.set('v.AssetsList', {'TypeLabel': 'Asset Type', 'TypeValue': '','TypeId': 'AssetType1', 
                               'AmountLabel': 'Asset Amount', 'AmountValue': '', 'AmountId': 'AssetAmount1'});
    var AssetList= cmp.get('v.AssetsList');
    var FactfindId = cmp.get('v.ffRecord.Id');
    var inputAssetListAction = cmp.get("c.inputAssetList");

    inputAssetListAction.setParams({
        "AssetList": AssetList,
        "FactfindId": FactfindId
    });

    inputAssetListAction.setCallback(this, function (response) {
        //store state of response
        var state = response.getState();
        if (state === "SUCCESS") {
            console.log(state);
            if (response.getReturnValue() != null) {
                // if getting any error while update the records , then display a alert msg/
                alert('The following error has occurred. while updating record-->' + response.getReturnValue());
            } else {
                console.log('check it--> update successful');
            }
        }
    });
    $A.enqueueAction(inputAssetListAction);   
public static void inputAssetList(list<String> AssetList, string FactfindId) {
    
    FactfindMultiples__c[] Assets = new List<FactfindMultiples__c>();
    
    for(Integer i=1;i<AssetList.size();i++)
    {
        FactfindMultiples__c Asset = new FactfindMultiples__c(Name='Asset' + i, 
                                                              AssetType__c= AssetList[i].TypeValue);
        Assets.add(Asset);
        
    }
}

I've tried syntax like AssetList[i].TypeValue but this returns errors.

Source Link
Owen
  • 13
  • 5

Passing List into Apex - Want to insert individual attributes from list

I'm having some difficulty with lists and apex.

I have a list declared in my lightning component, please see below:

<aura:attribute name="AssetsList" type="List" default="[]"/>

I then set some attributes in the controller upon intialisation. I have two input fields in the component, the first 3 attributes apply to one input and the last 3 apply to the other. Please see this below:

component.set('v.AssetsType', {'TypeLabel': 'Asset Type', 'TypeValue': '','TypeId': 'AssetType1', 
                               'AmountLabel': 'Asset Amount', 'AmountValue': '', 'AmountId': 'AssetAmount1'});

I have a save button in the component and when it is clicked it will run a method in the controller where I pass the list to the apex as a parameter.

    var AssetList = cmp.get('v.AssetsType');
    var FactfindId = cmp.get('v.ffRecord.Id');
    var inputAssetList = cmp.get("c.inputAssetList");

    inputAssetList.setParams({
        "AssetList": AssetList,
        "FactfindId": FactfindId
    });

    inputAssetList.setCallback(this, function (response) {
        //store state of response
        var state = response.getState();
        if (state === "SUCCESS") {
            console.log(state);
            if (response.getReturnValue() != null) {
                // if getting any error while update the records , then display a alert msg/
                alert('The following error has occurred. while updating record-->' + response.getReturnValue());
            } else {
                console.log('check it--> update successful');
            }
        }
    });
    $A.enqueueAction(inputAssetList);   

Once this parameter is in the apex, I'm then trying to insert a record to a custom object. I currently have this code.

public static void inputAssetList(list<String> AssestList, string FactfindId) {
    
    FactfindMultiples__c[] Assets = new List<FactfindMultiples__c>();
    
    for(Integer i=1;i<AssestList.size();i++)
    {
        FactfindMultiples__c Asset = new FactfindMultiples__c(Name='Asset' + i, 
                                                              AssetType__c= AssestList[i].TypeValue);
        Assets.add(Asset);
        
    }
}

I'm going through the Asset List and trying to push it into a new record for my custom object. Once this is done, I'll then add to a list of the new custom object which I'll insert.

The issue I'm having is for when I'm setting the AssetType__c custom field, I don't want to push every attribute for each part of the array. I just want to use the TypeValue attribute that I set in the list upon initialisation.

I've tried syntax like AssestList[i].TypeValue but this returns errors.

Any help would be massively appreciated.

Thank you,

Owen