You need to sign in to do that
Don't have an account?
jessie dong
Is there any way to create custom setting programmatically?
Hi,
Instead of create the custom settings manually from Setup-->Develop --> Custom Settings -->New , anyone know is any way to create them automatically in Apex class?
thanks in advanced!
Instead of create the custom settings manually from Setup-->Develop --> Custom Settings -->New , anyone know is any way to create them automatically in Apex class?
thanks in advanced!
There is no any automated mechanism to create custom setting records dynamically. You can either create a generic method which would check if there are any custom setting record and if is empty then perform a DML operation and insert it.
In one of my project, we created JSON files and created a generic logic which would parse the JSON and create custom setting record if those are missing.
Else, I would recommend to switch over to Custom Metadata Types that would help you to deploy in between environments.
Hope this helps.
Post further here if you have any other questions.
Happy Coding!!
All Answers
Greetings to you!
Please refer to the below links which might help you further with the above requirement.
https://developer.salesforce.com/forums/?id=906F0000000kJURIA2
https://salesforce.stackexchange.com/questions/24424/populating-custom-settings-field-using-apex
https://developer.salesforce.com/forums/?id=906F000000093d5IAA
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
My scenario is when my application starting, it will run a basic check, if the custom settings is not ready, it’s trigger some thread to setup the custom settings programmatically.
There is no any automated mechanism to create custom setting records dynamically. You can either create a generic method which would check if there are any custom setting record and if is empty then perform a DML operation and insert it.
In one of my project, we created JSON files and created a generic logic which would parse the JSON and create custom setting record if those are missing.
Else, I would recommend to switch over to Custom Metadata Types that would help you to deploy in between environments.
Hope this helps.
Post further here if you have any other questions.
Happy Coding!!