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
code redcode red 

Custom Setting; getting list data on VF page

Hi all;

 

I have a list type Custom Setting with one Custom Field which is used to populate a selectList on a VF page.

 

  • CS API Name; LaborType__c
  • Custom Field Label; Rate, API Name; Rate__c, Data Type; Currency
  • In the CS Data Details (the managed list); Name (e.g.) Mechanic, Rate (e.g.) $90

 

On the VF page supported by a custom object with Labor Type and Rate fields, and page controller with a selectList, the user selects a Labor Type (e.g.) Mechanic (the Name from the CS Custom Field list), and the related labor rate should populate the Rate field automatically.

 

Though I have read all the SF documentation and every post on the subject here, I cannot find an example of bringing the values of both of the CS Custom Fields to a VF page based on the selection of ONE of those values.

 

Eventually the labor rate (stored value) will be included in a formula; e.g., number of hours applied x labor rate, etc.

 

Thanks in advance for any suggestions or examples of how this might be done.

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

So the way that I'd handle that would be to store the mechanic and associated rate into a map, and then when the user selects a mechanic, retrieve the rate from the map and use that as required.  Does that help?  I'm not sure I quite understand how you are using it.

All Answers

bob_buzzardbob_buzzard

How are you making the custom settings available to the Visualforce page? Are you accessing them via DML in the controller or using the $ syntax on the page?

code redcode red

Hi Bob,

 

Thank you for the reply; here's the code from the VF page controller that returns the "Labor Type" name; e.g., Mechanic.

 

//Labor Types
lbt=[select name, Rate__c from LaborType__c];
laborTypes = new List<SelectOption>();
try {
List<LaborType__c> ltlist = [select name from LaborType__c];
for (LaborType__c lt: ltlist){
laborTypes.add(new SelectOption(lt.name,lt.name));
}
} catch (Exception e) {
throw e;
}

 

And this bit returns the "Rate":

 

//Labor Rates
laborRates = new List<SelectOption>();
try {
List<LaborType__c> lrlist = [select name,Rate__c from LaborType__c];
for (LaborType__c lr: lrlist){
laborRates.add(new SelectOption(lr.name, String.valueOf(lr.Rate__c)));
}
} catch (Exception e) {
throw e;
}
}

 

I am able to get both values to the VF page, but only separately. I'm hoping to bring the Rate value into my VF page by selecting just the Labor Type value.


Thanks in advance for any suggestions.

 

 

 

bob_buzzardbob_buzzard

So the way that I'd handle that would be to store the mechanic and associated rate into a map, and then when the user selects a mechanic, retrieve the rate from the map and use that as required.  Does that help?  I'm not sure I quite understand how you are using it.

This was selected as the best answer
code redcode red

That did the trick! Thank you! I'm learning new ways of using Custom Settings...