0

I have a select-option list which contains values as (eg: SystemIdops.add(new SelectOption(system1.id,system1.NEX_Friendly_Name__c))) id,name).

Name will be displayed in VF page ,when user select the item the "id" of the name will be fetched, but i want to get the "name(label)" and display in the <apex:outputtext> attribute.

Could anyone please help? Thanks

  • Do you mean that when a selection is made you want the name of the selection to update in the text field? You can do that with Visualforce re-rendering or for a more immediate response purely in the client using JavaScript (e.g. stackoverflow.com/questions/6315437/…). – Keith C Nov 17 '16 at 9:03
0

Create a map with same data like:

Map<Id, String> mapData = new Map<Id, String>();
mapData.put(system1.id,system1.NEX_Friendly_Name__c);

It depends how you create the map. You could create it while querying the data itself. and add a null key in the map to handle blank selection.

Now, you could display/use name from the map based on ID, any time.

{!mapData[selectedId]}
  • great! glad it helped :) – San Tosh Nov 17 '16 at 9:59
  • Getting error for null result form the query. Can you please tell us to handle null key in the map to handle blank selection. – Chithra Rengasamy Nov 17 '16 at 10:36
  • Tried adding mapData.put('Null' ,'None'); still getting error is it syntax not correct ? – Chithra Rengasamy Nov 17 '16 at 10:37
  • because id needs certain format...u can not use Strings...try converting Map<Id, String> to Map<String, String> – San Tosh Nov 17 '16 at 13:43

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.