Please Note: This is not a complete code. I am showing here only the concept. To understand the concept, you must have prior knowledge of fieldset. Please write your comment or mail me at sandeep.saini482@gmail.com if you want elaboration of full code.
public Map mapFieldLabels{get;set;}
//call this method in constructor
public methodTosetLabel() {
mapFieldLabels = new Map();
Schema.DescribeSObjectResult d = Contact.sObjectType.getDescribe();
Map mapFields = d.fields.getMap();
for (Schema.FieldsetMember member : getEnrollmentQuestionsFields()) {
if (member.fieldpath == 'Student_Type__c') {
mapFieldLabels.put(member.fieldpath,'I am a');
} else if (member.fieldpath == 'Program_of_Interest__c') {
mapFieldLabels.put(member.fieldpath,'What is your program of interest?');
} else {
mapFieldLabels.put(member.fieldpath,mapFields.get(member.fieldpath).getDescribe().getlabel());
}
}
}
public List getEnrollmentQuestionsFields(){
//EnrollmentQuestions is the fieldset
return Schema.SObjectType.Contact.fieldSets.EnrollmentQuestions.getFields();
}
Now assign map value to label as shown in below code.