0

I am getting the following error message from my VF page and controller extension. Does anyone know how to resolve?

apex:inputField can only be used with SObjects, or objects that are Visualforce field component resolvable.

VF Page:

<apex:page standardController="Contact" tabStyle="Contact" sidebar="false" extensions="RDATasks" action="{!RDA}">

<apex:form >

<apex:sectionHeader title="Revenue Driving Activities"/>

<apex:actionRegion>
<apex:outputPanel id="taskList">
<apex:repeat value="{!listTask}" var="tsk">
    <apex:pageBlock >
        <apex:pageBlockSection title="Main RDA">
            <apex:outputField value="{!Contact.Account.Name}" label="Related To"/>
            <apex:outputField value="{!Contact.Name}" label="Name"/>
            <apex:inputField value="{!tsk.Type_of_RDA__c}" style="width:35%"/>
            <apex:inputField value="{!tsk.Subject}" style="width:45%"/>
            <apex:inputField value="{!tsk.Type_Detail__c}" style="width:35%"/>
            <apex:inputField value="{!tsk.ActivityDate}" style="width:35%"/>
            <apex:inputField value="{!tsk.Status}" />
            <apex:inputField value="{!tsk.Description}" style="width:100%"/>
            <apex:inputField value="{!tsk.FollowUp__c}" style="width:100%">
                <apex:actionSupport event="onchange" rerender="taskList,followTask"/>
            </apex:inputField>
        </apex:pageBlockSection>

<apex:outputPanel id="followtask">
<apex:variable var="tskF" value="{!listTaskFollow}"/>
        <apex:pageBlockSection title="Follow-Up RDA" rendered="{!tsk.FollowUp__c}">
            <apex:outputField value="{!Contact.Account.Name}" label="Related To"/>
            <apex:outputField value="{!Contact.Name}" label="Name"/>
            <apex:inputField value="{!tskF.Type_of_RDA__c}" style="width:35%"/>
            <apex:inputField value="{!tskF.Subject}" style="width:45%"/>
            <apex:inputField value="{!tskF.Type_Detail__c}" style="width:35%"/>
            <apex:inputField value="{!tskF.ActivityDate}" style="width:35%"/>
            <apex:inputField value="{!tskF.Status}" />
            <apex:inputField value="{!tskF.Description}" style="width:100%"/>
        </apex:pageBlockSection>

</apex:outputPanel>
    </apex:pageBlock>
</apex:repeat>

</apex:outputPanel>
</apex:actionRegion>

    <apex:commandButton value="Add Another RDA" action="{!RDA}"/>
    <apex:commandButton value="Remove Last RDA" action="{!removeRDA}"/>
    <apex:commandButton value="Save RDAs" action="{!saveTask}"/>
</apex:form>

</apex:page>

Controller:

public with sharing class RDATasks{

    public list<Task> listTask{get;set;}
    public list<Task> listTaskFollow{get;set;}
    public integer n;

    Set<Task>Tasks = new Set<Task>();
    Set<Task>FollowTasks = new Set<Task>();

    private final Contact con;
    public RDATasks(ApexPages.StandardController myController){
        listTask = new List<Task>();
        listTaskFollow = new List<Task>();
        con=(Contact)myController.getRecord();
    }

//  Adds RDA Task to list
    public void RDA()
    {
        listTask.add(new Task(
           WhoId = con.Id,
           Status = 'Completed',
           ActivityDate = system.TODAY(),
           Subject = '',
           Description = '',
           OwnerId = UserInfo.getUserId(),
           WhatId = con.AccountId,
           RDA__c = TRUE,
           FollowUp__c = FALSE)
           );
    }

//  Adds RDA Follow-Up Task to list
    public void RDAfollow()
    {
        n=listTask.size() - 1;
        listTask[n].FollowUp__c = FALSE;
        listTaskFollow.add(new Task(
           WhoId = con.Id,
           Status = 'In Progress',
           ActivityDate = system.TODAY()+7,
           Subject = 'Follow-Up: '+listTask[n].Subject,
           OwnerId = UserInfo.getUserId(),
           WhatId = con.AccountId,
           RDA__c = TRUE,
           FollowUp__c = TRUE)
           );
    }

//  Saves list of RDA Tasks added
    public PageReference saveTask(){
        insert listTask;
        insert listTaskFollow;

        if(!listTaskFollow.isEmpty()){
            Tasks.addAll(listTask);
            FollowTasks.addAll(listTaskFollow);
        if(!Tasks.containsAll(FollowTasks)){
            integer last = listTaskFollow.size();
            listTask.add(listTaskFollow[last]);
        }
        }
        RDAfollow();
            {
            PageReference contactPage = new PageReference('/' + con.Id);
            contactPage.setRedirect(true);
            return contactPage;
            }
    }
}
0

Since apex:inputField can only be used with SObjects, or objects that are Visualforce field component resolvable.

So, probably this line onward you will receive the error.

Change <apex:inputField value="{!tsk.Type_of_RDA__c}" style="width:35%"/> to <apex:inputText value="{!tsk.Type_of_RDA__c}" style="width:35%"/>

And any <apex:outputField/> to <apex:outputText/>

You can try to explore the <apex:column> in this situation.

  • Thanks. One problem is those fields are picklists. Is there a way to keep that functionality? – John Neilan Jan 24 '17 at 22:00
  • do not use picklist as inputField – Santanu Boral Jan 24 '17 at 22:02
  • can you please close this question, if you are happy with the answer – Santanu Boral Jan 25 '17 at 19:37
0

you need to change the tag to inputtext.

0

It's quite likely that this is the culprit here:

<apex:variable var="tskF" value="{!listTaskFollow}"/>

You are then using the tskF variable in your code as though it is a Task object, when in reality it is a List<Task>, and an empty one at that. You will need to come up with a way of passing in a Task object from your controller to be used here instead.

As an aside, I would look at how you are populating the first value for listTask - currently, you are doing so by calling the RDA() method in the action attribute of the apex:page tag.

The documentation for the apex:page tag contains the following warning for the action attribute:

Important: This action should not be used for initialization or DML.

A better location for this call is in the constructor of your controller, as this is guaranteed to be called first on each page load. For more information see Order of Execution for Visualforce Page Get Requests

  • Does anybody know why page actions are recommended to not be used for initialization or DML? It's a common requirement to do a DML op on page load, and that's the workaround I've been using for years! – jkraybill Jan 25 '17 at 3:30

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.