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
Manoj DegaManoj Dega 

Urgent Issue on Custom Settings

I've a Custom Settings with Hierarchy, on that two fields Read__c, Unread__c.
integer i=10;
integer j=5;

query1='select id,name,is_read__c,(select id from Attachments where createddate < last_n_days :'+i+') from Account where is_read__C = false';

query2='select id,name,is_read__c,(select id from Attachments where createddate < last_n_days :'+j+') from Account  where is_read__C = true';

The Above Code Snippet Works Good. when we Use Custom Settings Value in not works.
AccountSetting__c acs =AccountSetting__c.getInstance();
integer i=integer.valueOf(acs.Read__c); //Read = 10
integer j=integer.valueOf(acs.Unread__c); //Unread = 20

query1='select id,name,is_read__c,(select id from Attachments where createddate < last_n_days :'+i+') from Account where is_read__C = false';
query2='select id,name,is_read__c,(select id from Attachments where createddate < last_n_days :'+j+') from Account where is_read__C = true';
Thanks in Advance
Best Answer chosen by Manoj Dega
MandyKoolMandyKool
Hi Manoj,

If you have defined the values for "Read__c" and "Unread__c" inside "Default Organization Level Value" under Hierarchical Custom Setting; then you will have to use getOrgDefaults() method.
so your code will be 

AccountSetting__c acs = AccountSetting__c.getOrgDefaults();

Hope this resolves your issue.

All Answers

MandyKoolMandyKool
Hi Manoj,

If you have defined the values for "Read__c" and "Unread__c" inside "Default Organization Level Value" under Hierarchical Custom Setting; then you will have to use getOrgDefaults() method.
so your code will be 

AccountSetting__c acs = AccountSetting__c.getOrgDefaults();

Hope this resolves your issue.
This was selected as the best answer
Subramani_SFDCSubramani_SFDC
change the Account to AccountSetting__c in 2nd SOQL QUERY...it will work i think