You need to sign in to do that
Don't have an account?
DianeM
Spring '10 Issue with Custom Settings that affects testing
I believe that there is a bug associated with custom settings.
I used the migration tool to create custom settings in an org I use for integration. Test methods that reference the custom setting get a null value when I attemp to retrieve the custom setting.
After I went into the org and manually set a value in the custom setting (it is a public hierarchy) and then removed the value, subsequent executions of the test code executed as expected and the retrieval of the custom setting result in a non-null result.
I am concerned that I have to manually make a change to the custom setting before it is visible to the apex code.
I used the migration tool to create custom settings in an org I use for integration. Test methods that reference the custom setting get a null value when I attemp to retrieve the custom setting.
After I went into the org and manually set a value in the custom setting (it is a public hierarchy) and then removed the value, subsequent executions of the test code executed as expected and the retrieval of the custom setting result in a non-null result.
I am concerned that I have to manually make a change to the custom setting before it is visible to the apex code.
All Answers
Yes - that is exactly what I am experiencing. I am concerned that this is going to affect my ability to package this app for the app exchange. My test code for the upload process has to skip everything that is associated with the custom settings.
Good to hear I am not the only one that saw this.
So it is a known limitation that custom settings defaults are not included in a pacakge.
This doesn't prevent you from testing them, as you seem to be aware. There was an issue with creating them in a test context but that was resolved.
For those reading this later, you can test your setting whether defaults have been established or not by doing something like this:
@IsTest
private class customSettingsTests {
static testmethod void basicOrgDefaultTest() {
My_Setting__c s = My_Setting__c.getOrgDefaults();
if(s == null) {
s = new My_Setting__c(SetupOwnerId = UserInfo.getOrganizationId());
}
s.enabled__c = true;
Database.upsert(s);
Id accountId;
if(My_Setting__c.getOrgDefaults().enabled__c) {
Account a = new Account(name = 'test');
Database.insert(a);
accountId = a.id;
}
System.assert(accountId != null);
}
}
When this limitation is addressed, getOrgDefaults() should not return null effectively. No ETA on when this will be addressed at this time unfortunately. Custom Settings are a relatively new feature so I wasn't surprised to not find this as an Idea on the IdeaExchange. If you create one (which I encourage you to do), please tag it to the Visualforce & Apex and Application Distribution categories and post a link on this thread back to it so others can find/vote on it easily. This will help us prioritize addressing this issue accordingly.
Thanks,
The idea is here:
https://sites.secure.force.com/ideaexchange/ideaView?c=09a30000000D9xt&id=08730000000GrLgAAK
Please vote for it.