4

I want to insert a record of custom setting of type List through Lightninng component using form/any other input UI.In doing so through form and using UIInputText, when I am using following markup to type something and then tab away, I am getting error as described:

<ui:inputText aura:id="textID" label="A field Name"
         class="slds-input"
         labelClass="slds-form-element__label"
         value="{!v.listCustomSettingVariable.Field__c}"

attribute:

<aura:attribute name="listCustomSettingVariable" type="ListCustomSetting__c" />

Error: Error in $A.getCallback() [Cannot read property 'Field__c' of null] Failing descriptor: {markup://ui:input}

This is similar to inserting Expence__c custom object as described here: https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/qs_aotp_app_step2_cmp.htm?search_text=form

0

I'd expect you to need a server side controller to pass the custom settings to the lightning component's controller. If you were using hierarchy custom settings, those could be related to either specific users or to profiles. In the case of a list setting, your component's controller first needs to be able to do something like below:

List<Games__C> mcs = Games__c.getall().values(); 

After which you can then associate the values with the fields. In the case of a hierarchy, you'd be getting an instance which you'd associate with the user profile or Id as below:

Hierarchy__c CS = Hierarchy__c.getInstance(SysAdminID);

Hierarchy__c CS = Hierarchy__c.getValues(RobertId);

As you can see from the above examples, all of these would best be retrieved from a server side controller. I'm not certain there are lightning component methods that support retrieving them directly as of yet.

EDIT:

Based on your comments, it sounds like you're either trying to edit the values of existing custom setting lists, or want to create new a instance of a custom setting list. Which one you want to do isn't clear. See Custom Setting Methods in the Apex Docs.

First, you're going to want to check to make certain that the list isn't 'read only'. If it isn't, obtain the name of the list. Once you have that, I believe you're probably still going to need a server side controller to either update any existing lists or insert new instances of lists with different names. You'll want to check the CRUD permissions for the list.

getAll() returns values for all custom fields associated with the list setting.

CustomSettingName__c mc = CustomSettingName__c.getValues(data_set_name);

Both getInstance(dataSetName) and getValues(dataSetName) return the custom setting data set record for the specified data set name.

To overwrite the default instance of a custom setting you can do something like the following:

My_Settings__c settings = new My_Settings__c();
settings.Page_Size__c = 5;
settings.debugging__c = true;
insert settings;  

If you wanted a new instance with a name of SettingList2, you'd need to modify the above to reflect that it's a new instance and assign the name before inserting it.

  • Thanks for your response. I want to associate values that are TAKEN FROM UI to fields. getall().values() returns list of values if I am not wrong. So probably that won't help. What I tried was I returned an empty instance of my custom setting from Apex (return new ListCustomSetting__c;) and then stored it in attribute in component. Now I was able to save values in respective fields using :value="{!v.listCustomSettingVariable.Field__c}. But on passing this instance back to server for insertion in DB, I am getting this error: "Unable to read SObject" Please let me know your thoughts. – Sarang Nov 11 '16 at 5:34
0

You need to change your attribute to :

<aura:attribute name="listCustomSettingVariable" type="ListCustomSetting__c" default="{'sobjectType':'ListCustomSetting__c', 'Field__c':''}"/>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.