1

I basically have standard controller and an apex extension. I need the standard controller to get the current record ID. Then in my extension i use that id to find other related records. When i try to pull these fields from the extra object i get this error: 'Invalid field Title for SObject EmailMessage'

<apex:page standardController="EmailMessage" extensions="EmailFilesApex" Action="{!RunSOQL}">
        <apex:pageBlock title="My Content">
      <apex:pageBlockTable value="{!ERecords}" var="Record">
       <apex:column >
        <apex:facet name="header">Account Title</apex:facet>
        <apex:outputText value="{!Record.Title}"/>
       </apex:column>
       <apex:column >
        <apex:facet name="header">Id</apex:facet>
        <apex:outputText value="{!Record.Id}"/>
       </apex:column>
      </apex:pageBlockTable>
    </apex:pageBlock>

    </apex:page>

//Class

public with sharing class EmailFilesApex {
public String currentRecordId {get;set;}
public String parameterValue {get;set;}
public Account acc{get;set;}
public List<ContentVersion> ERecords {get; set;}    

    public EmailFilesApex(ApexPages.StandardController controller) {
        currentRecordId  = ApexPages.CurrentPage().getparameters().get('id');
    }

    public void RunSOQL(){
        ERecords = [SELECT Title, Id, FileType FROM ContentVersion WHERE FirstPublishLocationId =:currentRecordId];

    }
}
1

The variable name in apex:pageBlockTable var attribute is causing the issue. if you change it to any other name your code will be saved properly. I have changed Record to variable for example:-

<apex:page standardController="EmailMessage" extensions="EmailFilesApex">
    <apex:pageBlock title="My Content">
        <apex:pageBlockTable value="{!ERecords}" var="variable">
            <apex:column >
                <apex:facet name="header">Account Title</apex:facet>
                <apex:outputText value="{!variable.Title}"/>
            </apex:column>
            <apex:column >
                <apex:facet name="header">Id</apex:facet>
                <apex:outputText value="{!variable.Id}"/>
            </apex:column>
        </apex:pageBlockTable>
    </apex:pageBlock>    
</apex:page>

Basically, When you are using StandardController, The below syntax are same:-

  1. {!Record.Title}
  2. {!EmailMessage.Title}

This is why, you were getting the Invalid field Title for SObject EmailMessage error because the there is no field with Title name on EmailMessage SObject.

-1

try this in constructor instead:

public EmailFilesApex(ApexPages.StandardController controller) {        
EmailMessage msg = (EmailMessage)controller.getRecord();
currentRecordId  = msg.id; }
  • hmm i seem to get: Incompatible types since an instance of Id is never an instance of EmailMessage – Nathan Marchant Dec 9 '19 at 10:41
  • sorry just just do this: EmailMessage msg = (EmailMessage)controller.getRecord(); currentRecordId = msg.id; – summer Dec 9 '19 at 10:42
  • That got rid of the incompatible type error but I'm still getting the Invalid field error on the VF side of things. – Nathan Marchant Dec 9 '19 at 10:45
  • I don't think getting the record id is the problem here this bit works :) – Nathan Marchant Dec 9 '19 at 10:51
  • This is a good example of why code dumps make poor answers. It didn't solve OP's problem, and with no explanation it led to a bunch of back-and-forth in the comments. Taking the time to explain what the issue is, how your solution works, and why your solution works is important. – Derek F Dec 9 '19 at 12:23

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.