You need to sign in to do that
Don't have an account?
krishna casukhela 7
unable to access custom setting in apex
Hi
I have created a custom setting whose api name is SonyMusicUK__c and added value to it as Sony Music UK
Now in my soql I want to refer to this custom setting but I am unable to do so
SonyMusicUK__c p; //create an object for custom setting
p=[select Name from SonyMusicUK__c];
system.debug(p);
List<subscription__c> lstsub=new List<subscription__c>();
lstsub=[select s.Mailing_List_Name__c
from subscription__c s
where s.Territory_ID__c.Territory__c LIKE (p)];
system.debug(lstsub);
system.debug(lstsub.size());
I am not getting desired result, any better way of doing this.
thanks
krishna
I have created a custom setting whose api name is SonyMusicUK__c and added value to it as Sony Music UK
Now in my soql I want to refer to this custom setting but I am unable to do so
SonyMusicUK__c p; //create an object for custom setting
p=[select Name from SonyMusicUK__c];
system.debug(p);
List<subscription__c> lstsub=new List<subscription__c>();
lstsub=[select s.Mailing_List_Name__c
from subscription__c s
where s.Territory_ID__c.Territory__c LIKE (p)];
system.debug(lstsub);
system.debug(lstsub.size());
I am not getting desired result, any better way of doing this.
thanks
krishna
Your code now becomes as below.
Apex Controller Method Visualforce Code Please do not forget to mark this thread as SOLVED and answer as the BEST ANSWER if it help you resolves your issue.
All Answers
a small change in query.
SonyMusicUK__c p;
p=[select Name from SonyMusicUK__c];
system.debug(p);
List<subscription__c> lstsub=new List<subscription__c>();
lstsub=[select s.Mailing_List_Name__c
from subscription__c s
where s.Territory__c : (p)];
system.debug(lstsub);
system.debug(lstsub.size());
Here Territory__c is a formula field in the object subscription__c
But when I execute I am getting error as Unexpectd token : near the where condition.
Thanks
krishna
The advantage of using custom settings is that the stored data is cached, and is made available with available library functions, without the need of a SOQL query to retrieve it. Althought Salesforce permits querying a custom setting, it is not recommended.
Your code now becomes
Refer the following link to understand Custom Settings better - https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_custom_settings.htm
Hope this helps.
Please do not forget to mark this thread as SOLVED and answer as the BEST ANSWER if it help you resolves your issue.
I got the desired result. thanks
I want to clarify one more point before I close this post.
I have created a new custom setting say Countries (api name : Countries__c) and has field CountryCode__c
this means
Afghanisthan AK
Australia AU
New Zealand NZ
Now I have the visualforce page as follows.
<apex:selectList value="{!fanCountry_Region}" size="1">
<apex:selectOption itemValue="None" itemLabel="--Select--"></apex:selectOption> <
apex:selectOption itemValue="United Kingdom" itemLabel="United Kingdom">
</apex:selectOption> <apex:selectOption itemValue="India" itemLabel="Germany">
</apex:selectOption> <apex:selectOption itemValue="SriLanka" itemLabel="Australia">
</apex:selectOption> <apex:selectOption itemValue="United States of America" itemLabel="United States of America">
</apex:selectOption>
</apex:selectList>
so I need to remove the above values and need to fetch the values from the custom setting .
Pls let me know what changes should I make to visualforce page and how to fetch values in controller for picklist.
thanks
krishna
Your code now becomes as below.
Apex Controller Method Visualforce Code Please do not forget to mark this thread as SOLVED and answer as the BEST ANSWER if it help you resolves your issue.
I able to populate the list of countries in picklist when the page loads.
Here I have a issue.
I have custom object fan__c which has say two fields country_region__c and email.
In browser URL I will append the encryptedID of the fan object and fetch the values into their respective fields in visual force page
assume in record we have country_region__c=India and email=abc@yahoo.co.in
so these values will appear in page but country is not coming in picklist.
Here is my code.
Thanks
krishna