0

I am trying to update a VF page and add a new field but am getting an error

Unknown property 'String.Id'

The field that I am trying to add is Descriptio__c, a depending picklist to Task_Type__c. All I was trying to do was add a new column and I added this to the query of the controller. Is anyone seeing anything that would cause this error?

Visual Force:

<apex:page controller="TimeTrackerTimesheetViewController" sidebar="false">
    <script>
    </script>

    <apex:form id="formie">
        <apex:pageblock id="blockie" title="Timesheet">

            <apex:outputPanel id="main_panel">

                <div style="margin:20px 0px">
                    <apex:actionRegion >
                        <apex:selectList value="{!dateSelected}" multiselect="false" size="1" >
                            <apex:actionSupport event="onchange" action="{!changeDate}" rerender="main_panel"/>
                            <apex:selectOptions value="{!availableDates}"/>
                        </apex:selectList>
                        <span style="font-size:14px; margin:0px 10px" >Total: {!totalHours} Hours</span>
                    </apex:actionRegion>
                </div>

                <apex:variable value="{!0}" var="xNum"/>  

                <apex:pageBlockSection columns="1" title="Time Entries" id="x_blocks" collapsible="False"> 
                    <apex:actionRegion >
                        <apex:pageBlockTable value="{!existingTTList}" var="xt"> 
                            <apex:column headerValue="Action" style="width:30px">
                                <apex:variable var="xNum" value="{!xNum + 1}"/>
                                <apex:commandLink value="Delete" style="color:red" action="{!removeXFromList}" rerender="main_panel" immediate="true">
                                    <apex:param value="{!xt.Id}" name="ttToDelete" assignTo="{!ttToDelete}"/>
                                </apex:commandLink>
                                <apex:commandLink value="Edit" style="color:blue;margin-left:10px;" action="{!editXFromList}" rerender="main_panel" immediate="true">
                                    <apex:param value="{!xt.Id}" name="ttToEdit" assignTo="{!ttToEdit}"/>
                                </apex:commandLink>
                            </apex:column>
                            <apex:column headerValue="Date" style="width:50px">
                                <apex:outputfield value="{!xt.Date__c}" />
                            </apex:column>
                            <apex:column headerValue="Account Name" style="width:100px">
                                <apex:outputfield value="{!xt.Account__c}" />
                            </apex:column>
                            <apex:column headerValue="Opportunity Name" style="width:100px">
                                <apex:outputfield value="{!xt.Opportunity__c}" />
                            </apex:column> 
                            <apex:column headerValue="Task Type" style="width:100px">
                                <apex:outputfield value="{!xt.Task_Type__c}" />
                            </apex:column>
                            <apex:column headerValue="Description" style="width:100px">
                                <apex:inputfield value="{!xt.Description__c}" required="true"/>
                            </apex:column>
                            <apex:column headerValue="Product Type" style="width:100px">
                                <apex:outputfield value="{!xt.Product_Type__c}" />
                            </apex:column>  
                            <apex:column headerValue="Notes" style="width:300px">
                                <apex:outputfield value="{!xt.Notes__c}" style="width:100%"/>
                            </apex:column>
                            <apex:column headerValue="Hours" style="width:100px">
                                <apex:outputfield value="{!xt.Time_Hours__c}" />
                            </apex:column>
                            <apex:inlineEditSupport showOnEdit="" event="ondblclick" changedStyleClass="myBoldClass"/>
                        </apex:pageBlockTable>
                    </apex:actionRegion>
                </apex:pageBlockSection>

                <apex:variable value="{!0}" var="rowNum"/> 

                <apex:pageBlockSection columns="1" title="Add Entries" id="p_blocks" collapsible="False"> 
                    <apex:pageBlockTable value="{!newTTList}" var="tt"> 
                        <apex:column headerValue="Action" style="width:50px">
                            <apex:commandLink value="Remove" style="color:red" action="{!removeRowFromList}" rendered="{!rowNum > 0}" rerender="main_panel" immediate="true" >
                                <apex:param value="{!rowNum}" name="rowToRemove" assignTo="{!rowToRemove}"/>
                            </apex:commandLink>
                            <apex:variable var="rowNum" value="{!rowNum + 1}"/>
                        </apex:column>
                        <apex:column headerValue="Date" style="width:50px">
                            <apex:inputfield value="{!tt.Date__c}" required="true"/>
                        </apex:column>
                        <apex:column headerValue="Account Name" style="width:100px">
                            <apex:inputField value="{!tt.Account__c}" required="true"/>
                        </apex:column>
                        <apex:column headerValue="Opportunity Name" style="width:100px">
                            <apex:inputField value="{!tt.Opportunity__c}" required="false"/>
                        </apex:column> 
                        <apex:column headerValue="Task Type" style="width:100px">
                            <apex:inputfield value="{!tt.Task_Type__c}" required="true"/>
                        </apex:column>
                        <apex:column headerValue="Description" style="width:100px">
                            <apex:inputfield value="{!tt.Description__c}" required="true"/>
                        </apex:column>
                        <apex:column headerValue="Product Type" style="width:100px">
                            <apex:inputField value="{!tt.Product_Type__c}" required="true"/>
                        </apex:column> 
                        <apex:column headerValue="Notes" style="width:300px">
                            <apex:inputfield value="{!tt.Notes__c}" style="width: 95%"/>
                        </apex:column>
                        <apex:column headerValue="Hours" style="width:100px">
                            <apex:inputfield value="{!tt.Time_Hours__c}" required="true"/>
                        </apex:column>
                    </apex:pageBlockTable>
                </apex:pageBlockSection>

                <apex:commandButton value="Add More" action="{!addNewRowToList}" rerender="main_panel" Status="status" immediate="true" />

            </apex:outputPanel>

            <apex:pageblockButtons location="bottom">
                <apex:commandButton id="savenew" value="Save" action="{!SaveTimeTrackers}"/>
            </apex:pageblockButtons>

        </apex:pageblock>
    </apex:form>

</apex:page>

Controller:

public class TimeTrackerTimesheetViewController {

    public String xt { get; set; }

    public List<Time_Tracker__c> newTTList {get;set;}
    public Integer rowToRemove {get;set;}
    public Id ttToDelete {get;set;}
    public Id ttToEdit {get;set;}
    public Date dateSelected {get;set;}
    public Decimal totalHours {get;set;}
    public List<Time_Tracker__c> existingTTList {get;set;}
    public List<SelectOption> availableDates {get;set;}
    public ID currentUser;

    public TimeTrackerTimesheetViewController(){
        currentUser = UserInfo.getUserId();
        dateSelected = date.today();
        totalHours = 0.0;
        rowToRemove = 0;
        availableDates = new List<SelectOption>();
        Date loopDate = date.today();
        availableDates.add(new SelectOption(loopDate.format(), 'TODAY ' + loopDate.format()));
        for(Integer i = 0; i < 7; i++) {
            loopDate = loopDate.addDays(-1);
            Datetime dt = loopDate.addDays(1);
            //if(dt.format('EEEE') != 'Sunday' && dt.format('EEEE') != 'Saturday'){
                availableDates.add(new SelectOption(loopDate.format(), dt.format('EEEE') + ' ' + loopDate.format()));
            //}
        }
        newTTList = new List<Time_Tracker__c>();
        addNewRowToList();
        queryExisting();
    }

    public void addNewRowToList(){
        Time_Tracker__c newTT = new Time_Tracker__c(Date__c = dateSelected, User__c = currentUser);
        newTTList.add(newTT);
    }

    public void removeRowFromList(){
        newTTList.remove(rowToRemove);
    }

    public void changeDate() {
        queryExisting();
        for(Time_Tracker__c t : newTTList) {
            t.Date__c = dateSelected;
        }
    }

    public void removeXFromList(){
        Database.delete(ttToDelete);
        queryExisting();
    }

    public void editXFromList(){
        Time_Tracker__c eTT = [SELECT User__c, Date__c, Account__c, Opportunity__c, Task_Type__c, Description__c, Product_Type__c, Time_Hours__c, Notes__c FROM Time_Tracker__c WHERE Id = :ttToEdit][0];
        //newTTList.clear();
        Time_Tracker__c newTT = new Time_Tracker__c(User__c = eTT.User__c, Date__c = eTT.Date__c, Account__c = eTT.Account__c, Opportunity__c = eTT.Opportunity__c, Task_Type__c = eTT.Task_Type__c, Description__c = eTT.Description__c, Product_Type__c = eTT.Product_Type__c, Time_Hours__c = eTT.Time_Hours__c, Notes__c = eTT.Notes__c);
        newTTList.add(0, newTT);
        Database.delete(ttToEdit);
        queryExisting();
    }

    public void queryExisting() {
        existingTTList = [SELECT Id, Date__c, Account__c, Opportunity__c, Task_Type__c, Description__c, Product_Type__c, Time_Hours__c, Notes__c FROM Time_Tracker__c WHERE Date__c = :dateSelected AND User__c = :currentUser];
        totalHours = 0.0;
        for(Time_Tracker__c e : existingTTList) {
            totalHours += e.Time_Hours__c;
        }
    }

    public PageReference SaveTimeTrackers(){
        insert newTTList;
        newTTList.clear();
        addNewRowToList();
        queryExisting();
        return null;
    }

}

1 Answer 1

3

You have a namespace collision between your pageBlockTable iteration variable and a property on your controller class.

<apex:pageBlockTable value="{!existingTTList}" var="xt"> 

public String xt { get; set; }

Since the property appears to be unused, you may wish to simply remove it. Visualforce is grabbing the xt property, which is a String and reasonably enough doesn't have an Id property.

1
  • Surprisingly.. It was an issue with my sandbox. I refreshed the sandbox tried it again and it worked.
    – SoleHack
    Oct 15, 2018 at 22:30

You must log in to answer this question.

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