+ Start a Discussion
sgoldberRHsgoldberRH 

Best Practice for querying field languages for multi langauge VF pages

Hi  -

 

I have a page with several fields on it. We are using the translation work bench to translate all the fields. Thus I don't want to hardcode in the field labels because I want them to appear in the users native language.  Below is a code segement I wrote to describe the object, and get the field labels. It works, but the next page I have to do this to has 150 fields, and I really would like to find a better way to do this. I am open to any suggetions. 

 

 

for (var i = 0; i < mdfObj.fields.length; i++){ if(mdfObj.fields[i].name == 'Channel_Account_Manager__c') camNameLabel = mdfObj.fields[i].label; if(mdfObj.fields[i].name == 'Channel_Account_Manager_Title__c') camTitleLabel = mdfObj.fields[i].label; if(mdfObj.fields[i].name == 'Channel_Account_Manager_Email__c') camEmailLabel = mdfObj.fields[i].label; if(mdfObj.fields[i].name == 'Channel_Account_Manager_Phone__c') camPhoneLabel = mdfObj.fields[i].label; if(mdfObj.fields[i].name == 'Channel_Account_Manager_Mobile_formula__c') camMobileLabel = mdfObj.fields[i].label; if(mdfObj.fields[i].name == 'Inside_Channel_Account_Manager__c') iCamNameLabel = mdfObj.fields[i].label; if(mdfObj.fields[i].name == 'Inside_Channel_Account_Manager_Title__c') iCamTitleLabel = mdfObj.fields[i].label; if(mdfObj.fields[i].name == 'Inside_Channel_Account_Manager_Email__c') iCamEmailLabel = mdfObj.fields[i].label; if(mdfObj.fields[i].name == 'Inside_Channel_Account_Manager_Phone__c') iCamPhoneLabel = mdfObj.fields[i].label; if(mdfObj.fields[i].name == 'Inside_Channel_Account_Manager_Mobile__c') iCamMobileLabel = mdfObj.fields[i].label; if(mdfObj.fields[i].name == 'Marketing_Program_Manager__c') mpmNameLabel = mdfObj.fields[i].label; if(mdfObj.fields[i].name == 'Marketing_Program_Manager_Title__c') mpmTitleLabel = mdfObj.fields[i].label; if(mdfObj.fields[i].name == 'Marketing_Program_Manager_Email__c') mpmEmailLabel = mdfObj.fields[i].label; if(mdfObj.fields[i].name == 'Marketing_Program_Manager_Phone__c') mpmPhoneLabel = mdfObj.fields[i].label; if(mdfObj.fields[i].name == 'Marketing_Program_Manager_Mobile__c') mpmMobileLabel = mdfObj.fields[i].label; }

 

 

 

henryCHhenryCH

Have a look at the describe methods of Dynamic Apex:

 

http://www.salesforce.com/us/developer/docs/apexcode/index.htm

 

 

You can create a Map of all SObject fields dynamically and get the labels.

 

Hope this helps.

 

Best regards,

Henry

sgoldberRHsgoldberRH

Henry

 

Thanks, but this is a visualforce page, and unless I am mistaken there is no way to create a map within it.