How to update Custom Settings value using Apex in Salesforce?

How to update Custom Settings value using Apex in Salesforce?

We can query or we can use getInstance() to get the value and then we can use update DML Operation to update the Custom Settings value.

Please check the following sample code for reference.

Sample Code:

Test__c obj = new Test__c(Name = 'Test');
insert obj;
Test__c t = Test__c.getInstance('Test');
t.Size__c = 908;
update t;

Here Test__c is a Custom Settings and Test is the name of the record.

Leave a Reply