I have been struggling with this problem for awhile and appreciate any help or suggestions to resolve this

In my ORDERS I have added a custom field "ClassTeacher_c", this is a custom lookup field which looks at CONTACTS which are type = Teacher.

In my Visualforce page, I have a table of orders displayed with the dropdown box of all the teachers available. The user of this page would assign a teacher to an order by selecting the teacher in the dropdown and then clicking the save link. I also have a inputtext box to record the wage that the teacher would be paid.

The problem I am facing is when I click save the teacher cannot be saved to the order even though the wage is saved correctly. Also the debug log I added to help track the issue is not longer displayed. This is strange because I know the code is being run because I can correctly save the wage.


<table id="classes" class="ordertable">

                    <tr id="{!o.OrderNumber}" class="tableheaderRow" >
                        <th rowspan="2"><button class="tbutton" value="{!o.OrderNumber}" onClick="return false">+</button></th>
                        <th> Class Id </th>
                        <th> Account Name </th>
                        <th> Programme </th>
                        <th> Programme Code </th>
                        <th> Class Start Date </th>
                        <th> Class End Date </th>
                        <th> Class Amount </th>
                        <th> Status </th>
                        <th> Teacher </th>
                        <th> </th>
                        <th> Teacher Wage </th>
                        <th> </th>

                    <tr id="test" class="tabledataRow" >   
                        <td>  <apex:outputLink value="/{!o.id}">{!o.OrderNumber}</apex:outputLink> </td>
                        <td> <apex:outputField value="{!o.AccountId}"/>  </td>
                        <td> <apex:outputField value="{!o.Programme__r.Name}"/> </td>
                        <td> <apex:outputField value="{!o.Programme_Code__c}"/> </td>
                        <td> <apex:outputField value="{!o.EffectiveDate}"/> </td>
                        <td> <apex:outputField value="{!o.EndDate}"/> </td>
                        <td> <apex:outputField value="{!o.Total_Cost_Of_Class__c}"/> </td>
                        <td> <apex:outputField value="{!o.Status}"/> </td>
                        <td> <apex:outputField value="{!o.ClassTeacher__c}" /></td>

                        <td> <apex:selectList value="{!o.ClassTeacher__c}" size="1"> 
                            <apex:selectOptions value="{!AllTeachers}" /> 
                        <td> <apex:outputField value="{!o.Teacher_Wage__c}"/> </td>      
                        <td> <apex:inputText value="{!o.Teacher_Wage__c}"/> </td>

                            <apex:commandLink action="{!saveClass}" value="save" onclick="return true">
                                <apex:param name="saveOrder" value="{!o.id}"/>


public with sharing class AllOrderController {

    List<OrderItem> aorderresults;
    Contact teacher; 

    public AllOrderController() {
        aorders = [
            SELECT Id, OrderNumber, AccountId, EffectiveDate , EndDate, Status, Total_Cost_Of_Class__c,
            ClassTeacher__r.Name, Teacher_Wage__c, Programme__r.Name, Programme_Code__c, ClassTeacher__r.Id, 
            FROM Order
            order by OrderNumber desc];
 public String selectedVal{get;set;}  

    public List<SelectOption > getAllTeachers(){     
        List<SelectOption> options = new List<SelectOption>();
        options.add( new SelectOption('0000','Choose Teacher'));
        for( Contact teacher : [ SELECT Id, Name FROM Contact WHERE Type__c = 'Teacher' order by Id desc] ) {
            options.add( new SelectOption(teacher.Id,teacher.name));
        return options;

public void saveClass() {
        string oid = ApexPages.currentpage().getParameters().get('saveOrder'); 
        Order singleRec = new Order();
        for (Order x: aorders) {
            if (oid == x.id) {
                singleRec = x;
        if (singleRec != null)
             System.debug('order ' +singleRec);
            System.debug('order number ' +singleRec.OrderNumber);
            System.debug('TEACHER WAGE ' +singleRec.Teacher_Wage__c);
            System.debug('TEACHER ' +singleRec.ClassTeacher__c);
        update singleRec;

1 Answer 1


I see that you are trying to set the Teacher Lookup field using the "value" option to a teacher.Id taken from the incoming select option:

<td> <apex:selectList value="{!o.ClassTeacher__c}" size="1"> 
     <apex:selectOptions value="{!AllTeachers}" /> 

Salesforce requires you to only use the data type of String when using the value option. You are trying to set it to a data type of Id. This may be your issue. Here is the documentation from Salesforce regarding the value option:

A merge field that references the controller class variable that is associated with this selectList. For example, if the name of the associated variable in the controller class is myListSelections, use value="{!myListSelections}" to reference the variable. If multiselect is true, the value attribute must be of type String[] or a List of strings. Otherwise, it must be of type String.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .