0

I'm getting below error when I used <apex:inputfield> instead of <apex:inputtext>,

apex:inputfield can only be used with sobjects or objects that are visualforce field component

But my requirement is to have inputfield so that a lookup to the user will be generated based on the lookup relationship given to the field.

VF Page

<apex:pageblockTable value="{!items}" var="item" columns="6" id="thetable">
                <apex:column headerValue="Internal Receipient">
                    <apex:inputText value="{!item.internalrec}"/><!-- **This should be Input field (Lookup Field)>Make field Required** -->
                  </apex:column>
</apex:pageblockTable>

Controller Class

public class BonusSplitclass {

public list<Fields_List> items;
    public void setitems(list<Fields_List> fielditem){
        items = fielditem;
    }
    public list<Fields_List> getitems(){
         if(items.isempty()){
            items = new list<Fields_list>();
            }
        return items;
    }
 public BonusSplitclass(ApexPages.StandardController controller) {
            string id = Apexpages.currentpage().getparameters().get('id');
            items = new list<Fields_List>();              
            for(integer i=0; i<5 ;i++){
                Fields_List fl = new Fields_List();
                bonus_split__c bs = new bonus_split__c();
                fl.internalrec = bs.Internal_Recipient__c;
                 items.add(fl);
}
Public class Fields_list{

    public string internalrec{get;set;}
}
}
2
  • 1
    You didnt paste` Fields_List` code?
    – Ashwani
    Jun 23 '15 at 10:42
  • This is the basic code I have written. What should be their in fields_list code?
    – Eagerin Sf
    Jun 23 '15 at 10:46
1

To start with you should use the apex:inputfield tag to make use of the default field functionality (lookup field in your case).

Second, you are using the value of 'internalrec' which is a regular String field instead of the Internal_Recipient__c (which I presume is the lookup field?) field from the Bonus_split__c Custom object.

In this case you should store the Bonus_Split__c record (for example as: public Bonus_Split__c bs) in the Fields_List wrapper class to call it in VF page like: {!item.bs.Internal_Recipient__c}.

0

Try below,

I have updated code to use field(Internal_Recipient__c) instead of string(internalrec) for input field,

Vf Page

<apex:pageblockTable value="{!items}" var="item" columns="6" id="thetable">
                <apex:column headerValue="Internal Receipient">
                    <apex:inputField value="{!item.b.Internal_Recipient__c}"/><!-- **This should be Input field (Lookup Field)>Make field Required** -->
                  </apex:column>
</apex:pageblockTable>

Controller Class

   public class BonusSplitclass {

    public list<Fields_List> items;
        public void setitems(list<Fields_List> fielditem){
            items = fielditem;
        }
        public list<Fields_List> getitems(){
             if(items.isempty()){
                items = new list<Fields_list>();
                }
            return items;
        }
       public BonusSplitclass(ApexPages.StandardController controller) {
                string id = Apexpages.currentpage().getparameters().get('id');
                items = new list<Fields_List>();              
                for(integer i=0; i<5 ;i++){
                    bonus_split__c bs = new bonus_split__c();
                    Fields_List fl = new Fields_List(bs);
                     items.add(fl);
                }
      }
      Public class Fields_list{

        public bonus_split__c b{get;set;}

        public Fields_list(bonus_split__c bs){
            b=bs;
        }
      }
    }

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.