function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

How do you update a field in Custom Settings?

I've created a hierarchical Custom Setting.  I'm looking to modify a field at the org level.


Given that my custom setting is called Test_config__c, and the field I want to update is Sample_field__c, here is some sample code:



Test_config__c aConfig = Test_config__c.getOrgDefaults();

aConfig.Sample_field__c = 'Some new value';



When I manage the custom value, the assignment hasn't been persisted.






Have you also tried,


update aConfig;





I did, but that didn't persist the change.


I ended up doing a dynamic soql query, updating the field, and the persisting it.  The problem here is that I can't guarantee the value that I use in the where clause to return the custom setting object will be consistent across orgs.


Anyone else have an idea? 


Hey there, I'm trying to understand exactly what you're trying to accomplish.  Maybe what you're doing and what you want to do aren't the same...


I did (in my test org):


abc__c aConfig = abc__c.getOrgDefaults();
aConfig.text__c = 'TERRORIZE';
update aConfig;


and the update is there.


Have you triied updating custom setting with VF page.


I am getting error while save.

sanket mahajan 1sanket mahajan 1
Hello Gliffydev,

Please follow the below link: