I have used the custom setting(Hierarchy) in visualforce page and we also used the namespace for the app.

When we access the field with namespace we are getting proper value, but we don't want to use the namespace while accessing the custom setting field. Without namespace value is not populating here. Can you suggest what may be the reason?

Edit: this is the VisualForce code:

    value="{!IF(VALUE(item.firstMon) ==
    ($Setup.Stos__Band_Ranges__c.Stos__Green_Band_End‌​__c*1000),'Won', )}"
    style="{!IF(VALUE(item.firstMon) <
    ($Setup.NS__Band_Ranges__c.NS__Red_Band_End__c*100),'color:#DB524B', 'N/A')}"/> 

NS – Namespace of the org. NS__Band_Ranges__c.NS__Red_Band_End__c value we are not getting here There might be some syntax issue, I understand those things.

  • When you say 'used the namespace for the app': is your app in a package? are your settings in a package? – mkorman Dec 11 '15 at 12:11
  • You should use namespace if you directly referencing the custom setting. – Ashwani Dec 11 '15 at 12:17
  • The symptoms you describe match this issue: salesforce.stackexchange.com/questions/47381/… although it should have been fixed in Winter 15 – mkorman Dec 14 '15 at 9:33

I'm missing some information here (as I posted in my comment above). I'm going to assume that your app is in a packiage, and that your settings are contained in the same package.

If that is the case, read on:

  • Whenever you access the custom settings from within your package you don't need to use the namespace.
  • Whenever you access it from outside your package, you need to use the namespace.

This is limitation is imposed by Salesforce by design. What if another developer, creating another package, came up with a settings object with the same name as yours? How can you tell them apart?

Edit: after your comment updates, the issue is that the "style" attribute is not evaluated as an expression (in the way that the "value" attribute is).

I would use 2 different tags and render them conditionally:

    value="{!IF(VALUE(item.firstMon) ==($Setup.Stos__Band_Ranges__c.Stos__Green_Band_End‌​__c*1000),'Won', )}"
    rendered="{!VALUE(item.firstMon) < ($Setup.NS__Band_Ranges__c.NS__Red_Band_End__c*100)}"

    value="{!IF(VALUE(item.firstMon) == ($Setup.Stos__Band_Ranges__c.Stos__Green_Band_End‌​__c*1000),'Won', )}"
    rendered="{!VALUE(item.firstMon) >= ($Setup.NS__Band_Ranges__c.NS__Red_Band_End__c*100)}"

Having said that, I would offload those calculations in the controller and expose them as booleans as properties. That will keep your display logic cleaner.

| improve this answer | |
  • more specifically, I can't able to access custom filed value inside the <apex:outputText> style tag? – Iqbal Dec 11 '15 at 12:53
  • Unfortunately I still need more information. Are the settings in a package? Is the Visualforce page you're working on in the same package? What does the page (or at least the tag) look like? What is the name of your custom settings object? Normally, page tags can access public properties in the controller. My guess (without any more info) is that you need to expose the value of the custom setting in the controller. – mkorman Dec 11 '15 at 12:59
  • Created package and we are accessing the custom settings values in Visualforce page and this page also resides in the same package. – Iqbal Dec 11 '15 at 13:13
  • In this case, I suspect the issue may be unrelated to the namespace at all. Can you please post your code (VF page, controller code, Custom settings class) so that we can help you a bit further? Thanks :) – mkorman Dec 11 '15 at 13:22
  • Code: <apex:outputText value="{!IF(VALUE(item.firstMon)==($Setup.Stos__Band_Ranges__c.Stos__Green_Band_End__c*1000),'Won', )}" style="{!IF(VALUE(item.firstMon) < ($Setup.NS__Band_Ranges__c.NS__Red_Band_End__c*100),'color:#DB524B', ‘N/A’)}"> NS – Namespace of the org. There might be some syntax issue, I understand those things. NS__Band_Ranges__c.NS__Red_Band_End__c value we are not getting here – Iqbal Dec 11 '15 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.