function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sravusravu 

Datatable error!! Unknow Property: String.Name

Hi,

 

I am getting a strange error when I am trying to display the colums in a datatable:

 

<apex:dataTable value="{!EmailAttachments}" var="ar

 <apex:dataTable value="{!EmailAttachments}" var="attach" columns="2" rendered="{!(attachments!=NULL)}" width="80%">
                <apex:column value="{!attach.Name}" headerValue="File Name" width="55px;"> 
                </apex:column>
                              <apex:column headerValue="Action" width="60px;">
                    <apex:commandLink Value="View" action="{!URLFOR($Action.Attachment.Download,attach.Id)}" target="_blank">
                        <apex:param name="attachment" value="{!attach.Id}" assignTo="{!attachmentId}"/>
                    </apex:commandLink>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
                    <apex:commandLink value="Remove" action="{!removeEmailAttachment}">                        
                        <apex:param name="attachment" value="{!attach.Id}" assignTo="{!emailaId}"/>
                    </apex:commandLink>
                </apex:column> 
            </apex:dataTable>  

 

 

and the controller method is:

 

 

  public List<Attachment> getEmailAttachments() {        
         //List<Attachment> attachment = 
         return [select Id, Name , BodyLength, CreatedById from Attachment where ParentId = :ApexPages.currentPage().getParameters().get('id') and Id in :emailattachId];        
         //return attachment;    
     }        
     
     public PageReference removeEmailAttachment(){        
         try{
             Attachment attach = [select Id, Name from attachment where id=:emailaId and ParentId = :ApexPages.currentPage().getParameters().get('id')];        
             delete attach;  
             return null;
         }catch(Exception e){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,e.getMessage()));
            return null;  
         }         
     } 

 

I am getting this strange error since two days. Is this a bug? Can anyone help me with this issue.

 

 

Best Answer chosen by Admin (Salesforce Developers) 
sravusravu

Finally solved the issue. I changed the getter method name and it is working fine now.

All Answers

ColinKenworthyColinKenworthy
rendered="{!(attachments!=NULL)}" 



maybe that should be EmailAttachments  ?

 

 

 

sravusravu

Hi,

 

Even if I change that also it is giving me the same error.

kiranmutturukiranmutturu

use like this

rendered="{!attachments} != NULL"
Rahul S.ax961Rahul S.ax961

Try This:

 

rendered="{!IF(attachments!=null, true, false)}"

 

Just match the proper condition, i mean true and false.

Hope it helps.

bob_buzzardbob_buzzard

This error indicates that somewhere in the page a String property has been assumed to be an sobject, and an attempt has been made to access the Name field on that property.

 

The only candidate for this in the code that has been posted is:

 

 

<apex:column value="{!attach.Name}" headerValue="File Name" width="55px;"> 

 

 

However, the code that you have posted clearly shows that attach is an instance of the sobject type Attachment.

 

Do you have any other markup like this in your VF page?  

 

 

sravusravu

Even if I changed that Var value then also it is giving me the same error:

 

 

         <apex:dataTable value="{!EmailAttachments}" var="a" columns="2" rendered="{(!EmailAttachments)!=NULL}">
             <apex:column>
                 <apex:outputText>{!a.Id}</apex:outputText>
             </apex:column>
         </apex:dataTable>

 

There is another dataTable on my page that I have written a month ago. That is working fine. The new dataTable that I added is causing me the error.

 

sravusravu

This works fin when I am using <apex:repeat>. It is not working with <apex:dataTable> and <apex:dataList>

bob_buzzardbob_buzzard

Can you post your full controller and page, plus the exact error message, including any line number etc?

sravusravu

Finally solved the issue. I changed the getter method name and it is working fine now.

This was selected as the best answer
ColinKenworthyColinKenworthy

... and what did you change it to in order to fix the problem ?

sravusravu

The get Method name in the controller. Instead of using getEmailAttachments() i used getEmailFiles(). May be it might have been conflicting with the other variables in the controller.