I am getting error "Unknown property 'VisualforceArrayList.EHS_Task__c'" while deploying VF page. Below is the page code:

<div style="border-bottom: 1px solid gray;border-right: 1px solid gray;padding: 2px 10px;">
                    <strong class="" >Task:</strong>
                    <input type="text" name="task" id="task" class="frminput" value = "{!getEHS.EHS_Task__c}"></input>


public  class ES_EHSReportGeneration {

    public Apexpages.Standardcontroller cntrl ;     
    public PageReference page; 
    public String id ='' ;
    public List<EHS_Pre_Job_Brief__c> getEHS{get;set;}
public ES_EHSReportGeneration(ApexPages.StandardController controller) {
            this.cntrl = controller ; 
            this.page = ApexPages.currentPage();
            this.id = page.getParameters().get('id');

 public ES_EHSReportGeneration(){

    getEHS = [Select id, EHS_Task__c from EHS_Pre_Job_Brief__c where id= :id limit 1] ; 


Please check and advise what am I doing wrong.

1 Answer 1

public List<EHS_Pre_Job_Brief__c> getEHS{get;set;}

This is a list of items. You need to access the zeroth index:

<input type="text" name="task" id="task" class="frminput" 
  value="{!getEHS[0].EHS_Task__c}" />

At this point, you'd get an index out of bounds error if no record is found. I'd refactor this to use a single variable instead of a List.

Note that you also don't even need the query here, as the Standard Controller interface gives you the record with the data you need if you don't use variable like getEHS.

<input type="text" name="task" id="task" class="frminput" 
  value="{!EHS_Pre_Job_Brief__c.EHS_Task__c}" />

By using the object's name, the Visualforce controller will automatically include it in a query that it does automatically for Visualforce pages.

You must log in to answer this question.

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