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
Jerun JoseJerun Jose 

Custom Setting data causing problem in Test method

Hi,

 

As of Spring 12 release, test methods by default do not have access to the org's data.

For this purpose, I inserted custom setting data in my test method. However, I am having trouble accessing them.

 

The puzzling thing is that CustomSettting.getAll() works but CustomSettting.getValues('value1') does not.

 

Below is a piece of the code from the test method.

system.debug('@@@@@@@@@@ CConList = '+CConList);
system.debug('@@@@@@@@@@ CRO_Constants__c.getAll() = '+CRO_Constants__c.getAll());
system.debug('@@@@@@@@@@ CRO_Constants__c.getAll().get() = '+CRO_Constants__c.getAll().get('Account Record Type'));
system.debug('@@@@@@@@@@ CRO_Constants__c.getValues = '+CRO_Constants__c.getValues('Account Record Type'));
system.debug('@@@@@@@@@@ CRO_Constants__c.getInstance = '+CRO_Constants__c.getInstance('Account Record Type'));

 The debug for this is as below.

 

14:16:31.185 (2185341000)|USER_DEBUG|[75]|DEBUG|@@@@@@@@@@ CConList = (CRO_Constants__c:{Name=Account Record Type, Id=a1tL00000004CkKIAU, Value__c=01220000000E1rrAAC}, CRO_Constants__c:{Name=Contact Record Type, Id=a1tL00000004CkLIAU, Value__c=012200000009cEAAAY}, CRO_Constants__c:{Name=Product Record Type, Id=a1tL00000004CkMIAU, Value__c=012200000009cEEAAY}, CRO_Constants__c:{Name=Standard PriceBook, Id=a1tL00000004CkNIAU, Value__c=01s2000000008FW}, CRO_Constants__c:{Name=CRO PriceBook, Id=a1tL00000004CkOIAU, Value__c=01sL0000000CpIEIA0})

14:16:31.196 (2196917000)|USER_DEBUG|[76]|DEBUG|@@@@@@@@@@ CRO_Constants__c.getAll() = {Account Record Type=CRO_Constants__c:{Name=Account Record Type, SetupOwnerId=00DL000000092uI, CurrencyIsoCode=PicklistData: USD, LastModifiedById=005D00000025yYr, SystemModstamp=2012-03-08 08:46:29, CreatedById=005D00000025yYr, CreatedDate=2012-03-08 08:46:29, LastModifiedDate=2012-03-08 08:46:29, IsDeleted=false, Value__c=01220000000E1rrAAC, Id=a1tL00000004CkK}, CRO PriceBook=CRO_Constants__c:{Name=CRO PriceBook, SetupOwnerId=00DL000000092uI, CurrencyIsoCode=PicklistData: USD, LastModifiedById=005D00000025yYr, SystemModstamp=2012-03-08 08:46:29, CreatedById=005D00000025yYr, CreatedDate=2012-03-08 08:46:29, LastModifiedDate=2012-03-08 08:46:29, IsDeleted=false, Value__c=01sL0000000CpIEIA0, Id=a1tL00000004CkO}, Contact Record Type=CRO_Constants__c:{Name=Contact Record Type, SetupOwnerId=00DL000000092uI, CurrencyIsoCode=PicklistData: USD, LastModifiedById=005D00000025yYr, SystemModstamp=2012-03-08 08:46:29, CreatedById=005D00000025yYr, CreatedDate=2012-03-08 08:46:29, LastModifiedDate=2012-03-08 08:46:29, IsDeleted=false, Value__c=012200000009cEAAAY, Id=a1tL00000004CkL}, Product Record Type=CRO_Constants__c:{Name=Product Record Type, SetupOwnerId=00DL000000092uI, CurrencyIsoCode=PicklistData: USD, LastModifiedById=005D00000025yYr, SystemModstamp=2012-03-08 08:46:29, CreatedById=005D00000025yYr, CreatedDate=2012-03-08 08:46:29, LastModifiedDate=2012-03-08 08:46:29, IsDeleted=false, Value__c=012200000009cEEAAY, Id=a1tL00000004CkM}, Standard PriceBook=CRO_Constants__c:{Name=Standard PriceBook, SetupOwnerId=00DL000000092uI, CurrencyIsoCode=PicklistData: USD, LastModifiedById=005D00000025yYr, SystemModstamp=2012-03-08 08:46:29, CreatedById=005D00000025yYr, CreatedDate=2012-03-08 08:46:29, LastModifiedDate=2012-03-08 08:46:29, IsDeleted=false, Value__c=01s2000000008FW, Id=a1tL00000004CkN}}

14:16:31.201 (2201417000)|USER_DEBUG|[77]|DEBUG|@@@@@@@@@@ CRO_Constants__c.getAll().get() = CRO_Constants__c:{Name=Account Record Type, SetupOwnerId=00DL000000092uI, CurrencyIsoCode=PicklistData: USD, LastModifiedById=005D00000025yYr, SystemModstamp=2012-03-08 08:46:29, CreatedById=005D00000025yYr, CreatedDate=2012-03-08 08:46:29, LastModifiedDate=2012-03-08 08:46:29, IsDeleted=false, Value__c=01220000000E1rrAAC, Id=a1tL00000004CkK}

14:16:31.201 (2201558000)|USER_DEBUG|[78]|DEBUG|@@@@@@@@@@ CRO_Constants__c.getValues = null

14:16:31.201 (2201676000)|USER_DEBUG|[79]|DEBUG|@@@@@@@@@@ CRO_Constants__c.getInstance = null

 Can someone explain me why I am getting null when using getValues and getInstance methods?

 

Thanks,

 

Jerun Jose

Best Answer chosen by Admin (Salesforce Developers) 
Jerun JoseJerun Jose
It seems that this issue has been fixed. I recently tried out the use case mentioned above in API v27.0 and it worked.

All Answers

Jerun JoseJerun Jose

I finally got a response from SFDC support for this. Unfortunately its no good news.

 

It looks like developer support is NO Support. They just told me.. yeah it doesnt work. Can I close the case? :smileyfrustrated:

Jerun JoseJerun Jose
It seems that this issue has been fixed. I recently tried out the use case mentioned above in API v27.0 and it worked.
This was selected as the best answer