+ Start a Discussion
ForceRookieForceRookie 

How to save list of records in Custom Settings through Aura Controller

Help me to upsert records to Custom Settings (List)

<aura:attribute name="myCustSettings" type="myCustomSettings__c[]"/>
<table class="slds-table slds-table--bordered slds-table--cell-buffer slds-table--striped slds-max-medium-table--stacked-horizontal"
	   role="grid">
	<thead>
		<tr>
			<th class="slds-is-sortable slds-cell-wrap" scope="col">
				Object
			</th>
			<th class="slds-is-sortable slds-cell-wrap" scope="col">
				Field
			</th>
			<th class="slds-is-sortable slds-cell-wrap" scope="col">
				Value
			</th>
			<th class="slds-is-sortable slds-cell-wrap" scope="col"></th>
		</tr>
	</thead>
	<tbody>
		<aura:iteration items="{!v.myCustSettings}" var="obj" indexVar="index">
			<tr class="slds-hint-parent">
				<td role="gridcell" data-label="Object">
					<div data-label="Object">
						<lightning:combobox type="text" aura:id="object"
											name="object"
											placeholder="-Select-"
											value="{!obj.Object__c}"
											options="{!v.objectList}"
											onchange="{!c.handleObjChange}"/>
					</div>
				</td>
				<td role="gridcell" data-label="Field">
					<div data-label="Field">
						<lightning:combobox aura:id="field"
											name="field"
											placeholder="-Select-"
											value="{!obj.Field__c}"
											options="{!v.fieldList}"
											onchange="{!c.handleFldChange}"/>
					</div>
				</td>
				<td role="gridcell" data-label="Value">
					<div data-label="Value">
						<lightning:input type="text" aura:id="value"
										 name="value"
										 placeholder="Type here"
										 placeholder="Type here"
										 value="{!obj.Value__c}"/>
					</div>
				</td>
				<td>
					<a onclick="{!c.removeRow}" data-record="{!index}">
						<lightning:icon iconName="utility:delete" size="small" alternativeText="Delete"/>
						<span class="slds-assistive-text">Delete</span>
					</a>
				</td>
			</tr>
		<!--/aura:iteration-->
	</tbody>
</table>
<div class="slds-grid" style="margin-bottom:15px;margin-top: 30px;text-align:center;">
	<lightning:button aura:id="add"
					  label="+ Add another row"
					  class="slds-m-top--medium"
					  variant="brand"
					  onclick="{!c.btnAdd}"/>
</div>

User-added image
Raj VakatiRaj Vakati
You can insert them like below 

https://salesforce.stackexchange.com/questions/148095/how-to-insert-list-custom-setting-entry-from-a-lightning-component
https://www.forcetalks.com/blog/using-custom-settings-in-salesforce/
http://www.vinaychaturvedi.com/blog/display-and-select-list-of-records-using-wrapper-class-in-lightning-component/
https://medium.com/@amster/building-a-real-time-filtered-list-with-custom-lightning-components-c33c82a07549
https://www.jitendrazaa.com/blog/salesforce/lightning-data-services-standard-controller-for-lightning-components/
My_Settings__c settings = new My_Settings__c();
settings.Page_Size__c = 5;
settings.debugging__c = true;
insert settings;

 
ForceRookieForceRookie

Hi Raj, thanks for the reply but I already solved it yesterday.

Ahm, will you answer my new question here? -- https://developer.salesforce.com/forums?id=9062I000000IHvDQAW

Raj VakatiRaj Vakati
Great ... Close this thread ! 
ForceRookieForceRookie
I'm sorry Raj, but I'm getting an error on saving. What's wrong with the code?
saveCustList: function(component){
        var set = component.get("v.myCustomSettings");
		console.log('set:' + set);
		var action = component.get("c.saveCustListSettings");
        action.setParams({"save" : set});
		action.setCallback(this, function(response) {
			var state = response.getState();
			console.log('state: ' + state);
			if (state === "SUCCESS") {
				if(response.getReturnValue() == true){
					console.log('SUCCESS');
				}	
			}
		});
		$A.enqueueAction(action);
    },
 
@AuraEnabled
    public static void saveCustListSettings(List<myCustomSettings__c> save){
        List<myCustomSettings__c> saveCS = new List<myCustomSettings__c>();
        saveCS = save;
        upsert saveCS;
    }
User-added image