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.AssetsList', {'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.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);
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> 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'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 AssetList[i].TypeValue but this returns errors.
Any help would be massively appreciated.
Thank you,
Owen
AssetsType
, and are you gettingAssestList
in Apex? try with debug log