Update value of Custom Settings from Apex | Salesforce



Hello everyone, in this article you will learn how you can update value of a custom settings from a Apex Class.


The main advantage of using custom settings is that its data is available in Application cached memory, that's why it is more efficient and having fast access over the application. And we can get the custom settings data using some methods available for the custom settings, hence no need to waste SOQL to fetch the data.

In below code mySettings__c is my custom setting, myCustomField is the name and fieldName__c is my field name in custom settings.



1
2
3
4
5
6
7
public class updateCustomSettingsCtrl {
    public updateCustomSettingsCtrl(){
        mySettings__c obj = mySettings__c.getInstance('myCustomField');
        obj.fieldName__c = 'New Data';
        update obj;
    }
}


 If you have any question please leave a comment below.
If you would like to add something to this post please leave a comment below.
Share this blog with your friends if you find it helpful somehow !

Thanks
Keep Coding 

Post a Comment

0 Comments