1
votes

I have looking everywhere for this kind of problem, but I have found nothing about it. Is there possible to update custom settings using just javascript code in Salesforce?

Custom Settings can be accessed using:

<script  type="text/javascript">
    var url = "{!$Setup.MyCustomSet__c.URL__c}";
    alert(url);
</script>

There is solution to pass javascript variable to Apex and then insert in custom settings, but i am looking for direct way of doing that. Any direction would be great.

2

2 Answers

0
votes

Custom settings are supposed to be relatively static data that can be used to avoid querying their database. Setting one via JS kind of defeats the purpose. What are you trying to do?

0
votes

I find out the solution. Basically its the same as the standard or custom object, just query the API name of custom settings object and set the preferred values.

Here is example of the code:

sforce.connection.sessionId = "{!$Api.Session_ID}";
var custom_sett_obj = new sforce.SObject("custom_settings_obj__c");
console.log(custom_sett_obj);

custom_sett_obj.Last_Name__c = 'Test';
var result = sforce.connection.create([custom_sett_obj]);

if (result[0].getBoolean("success")) {
    alert("Record " + result[0].id + " created!");
} else {
    alert("failed to create " + result[0]);
}