You need to sign in to do that
Don't have an account?

Update Custom Setting Field Value
I have a Hierarchy Custom setting with one field IsProcessed.
My batch apex will run only when the value of IsProcessed is true. After processing I need to update the value to false. I doubt whether it is possible.
Is there a way I can update a custom setting field value using apex.
Appreciate your help.
Yes you can update custom settings using Apex. Custom settings are just Custom Objects that have been specialised in certain specific ways. You can Retrieve custom setting records using either CustomSetting__c.get('value') or [SELECT id FROM CustomSetting__c WHERE name = 'value'];
Once retrieved you can update the setting by using the 'update' keyword as you would with any other object.
Cheers,
Wes
All Answers
Custom setting is like global utiliity data and ideally they are not for updating. do you have any specific reason for using custom setting in place of using some class level variable?
Yes you can update custom settings using Apex. Custom settings are just Custom Objects that have been specialised in certain specific ways. You can Retrieve custom setting records using either CustomSetting__c.get('value') or [SELECT id FROM CustomSetting__c WHERE name = 'value'];
Once retrieved you can update the setting by using the 'update' keyword as you would with any other object.
Cheers,
Wes
Thanks Wes.
I do not know we can use an update statement. I was looking for a custom setting method.
Please check below code to update custom settings from Apex.
Reference : https://www.salesforcebolt.com/2020/05/update-value-of-custom-settings-from.html
Please find the solution in the below link:
https://sfdc-concepts.blogspot.com/2021/12/update-custom-settings-in-apex.html?m=1