+ Start a Discussion

Accessing Data on Referenced Objects from Tasks

Good Morning Everyone,
I am trying to access information on a contact from a task which is referencing it. When I use the following syntax I receive an error that phone is not a valid field. I assume this is because the field is a lookup for either a contact or a lead. So how do I get the phone number out?
Thanks in advance for your help.
<apex:page standardController="Task" >
    <iframe id="dialer" style="display:none"></iframe>
    <apex:form >
        <apex:pageBlock title="Task Detail">
            <apex:pageBlockButtons >
                <apex:commandButton action="{!edit}" value="Edit" id="editButton"/>
                <apex:commandButton action="{!delete}" value="Delete" id="deleteButton"/>
            <apex:pageBlockSection title="Details" showHeader="false">
                <apex:pageBlockSectionItem >
                    Assigned To
                    <apex:outputField value="{!task.owner.name}" />
                </apex:pageBlockSectionItem >
                <apex:outputField value="{!task.priority}" />
                <apex:outputField value="{!task.subject}" />
                <apex:outputField value="{!task.activitydate}" />
                <apex:pageBlockSectionItem >
                    Task Record Type
                    <apex:outputField value="{!task.recordtype.name}" />
                </apex:pageBlockSectionItem >
                <apex:outputField value="{!task.status}" />
                <apex:pageBlockSectionItem >
                    Related To
                    <apex:outputField value="{!task.what.name}" />
                </apex:pageBlockSectionItem >
                <apex:outputField value="{!task.result_date__c}" />
                <apex:outputField value="{!task.who.name}" />
                <apex:outputField value="{!task.closed_by__c}" />
                <apex:outputField value="{!task.who.phone}" />


Message Edited by mtbclimber on 12-06-2008 11:40 AM
Yeah the WhoId on the Task is a special kind of lookup in that it can reference multiple types of objects. So I don't think you can use a lookup expression in the same way you can do for other fields. I tried this out using Apex and was able to get the Phone number in this way:

public class TestExpr {
public static testMethod void test() {
Task t = [SELECT WhoId, Subject FROM Task WHERE Subject='blah'];
Contact c = [SELECT Phone FROM Contact WHERE Id=:t.WhoId];

But of course, this would involve using a custom controller. Not sure if you've tried that kind of thing out yet?

No, I have not done a custom controller yet. Looks like I am going to have some fun this weekend.  :smileywink:
Let me know if you have any trouble with it :)