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
Edwin HerreraEdwin Herrera 

Display content different from the value

I am pulling fields from a database to my object on salesforce. one of the fields from the database are ID"s each ID represents a color such as ID 1111 is color green and 2222 is color yellow. The database does not have the actual color fields just the id for the color. How can I pull the ID's from the database but display Green, Yellow, or Red as the value on salesforce?
Siddharth ManiSiddharth Mani
Over the top all I can think of is to create a map. Something like:
Map<Integer, String> colorIndex = new Map<Integer,String>();
Populate this map with ID as the key and color as the value. Then you will be able to retrieve the same and display the colors as needed.


Edwin HerreraEdwin Herrera
Any idea is good with me. I am new to salesforce so how would I start a map and where would that code go that you have provided?
If there are any other ideas I would always try those as well.
Siddharth ManiSiddharth Mani
Need more details to give you a definite answer. Like where do you want to display this value (VF Page or Stanrd Page), what are the Object/Field Names, how is this update supposed to happen (when a record is created/updated or after editing), how many such colors will be there etc.
Edwin HerreraEdwin Herrera
I understand.
I would like to display in a visualforce page. The object api is Work_Item__c. The fields api are; Budget_Health__c, Schedule_Health__c, Overall_Health__c, and Quality_Scope_Health__c. These color ids would be pulled from the database and converted to an actual color. I would also like these fields to be editable between the different colors on the visual force page if possible. The colors are Blank, Green, Yellow, and Red. I only need the word displayed not the actual color.
Siddharth ManiSiddharth Mani
You can use the logic I gave earlier in your Visualforce Page controller. Should do the trick. Once the Map gets created, the values can be displayed in the page using <apex:outputText> or something.
Edwin HerreraEdwin Herrera
How do I call the map method on the visualforce page? also, since I have multiple fields that need a colorID to be translated how do I process the map for each field? below is what I have and I am stuck on how it is suppose to work. I thought that the map would automatically convert anything that has those numbers.

Map<Integer, String> colorIndex = new Map<Integer,String>();

Also if I want all the values translated when the page is loaded where on the controller would I place this map or method?