I have a custom object Team member contains four text fields First Name , Surname, location and job title and First Name and Surname is a required fields (When i create them i make them required).
and I have a Controller like :
public class TeamMemberController {
private Team_Member__c teamMember;
public TeamMemberController (ApexPages.StandardController stdController) {
this((Team_Member__c) stdController.getRecord());
}
private TeamMemberController (Team_Member__c teamMember) {
this.teamMember = teamMember;
}
public Team_Member__c GetTeamMember(){
return teamMember;
}
public List<String > GetFieldsNames () {
List<String> myList = new List<String>();
myList.add('Job_Title__c');
myList.add('Location__c');
return myList;
}
}
and VF page like :
<apex:page standardController="Team_Member__c" extensions="TeamMemberController">
<apex:form >
<apex:pageMessages />
<apex:pageBlock title="{!teamMember.name}" mode="edit">
<apex:pageBlockButtons >
<apex:commandButton action="{!cancel}" value="Cancel" immediate="true" />
<apex:commandButton action="{!save}" value="Save" />
</apex:pageBlockButtons>
<apex:pageBlockSection title="Team Member Details" columns="1">
<apex:inputField value="{!teamMember.First_Name__c}" style="width:250px;" />
<apex:inputField value="{!teamMember.Surname__c}" style="width:250px;" />
<apex:repeat value="{!fieldsNames}" var="myTeamMemberFieldName">
<apex:pageBlockSectionItem >
<apex:outputLabel value="{!myTeamMemberFieldName}" />
<apex:inputText id="myInputField" value="{!teamMember[myTeamMemberFieldName]}"
required="true" />
</apex:pageBlockSectionItem>
</apex:repeat>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
but when i run this code , and do the below steps, I found that I can't submit the form even if i entered a data in the field as the validation doesn't see the field value.
Steps :
- Fill the first name and surname
- Submit the form, you will find error saying you have to enter the job tile only without mentioning the location although both of them are required.
- Enter some data into the job title and press submit
- The validation error will be thrown saying Job title is required although there is a value on the field.