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
Shephali SwarnkarShephali Swarnkar 

how to get the task list assigned to any contact

Hi All,
In contact standard object we can assign new task to any contact we have. but now i need to get the updates regarding each task assigned to any contact.How to achieve this???
Best Answer chosen by Shephali Swarnkar
CongnizentCongnizent
hmmm , this is my mistake actually , here we can not query owner as it's look up of Lookup(User,Calendar) . So you can try owner.Name if you want name of user .

So finally try it .  Hope it will work 


public class tasklst {

    public List<task> tasklist {get;set;}
    public tasklst() {
    tasklist =[Select subject,Priority, status, ActivityDate,Owner.Name from task ];
    }

}
 

All Answers

CongnizentCongnizent
Hi , 

On task view screen , there is a field 'Assigned To' referring contact it's related to . 
Please let me know what exactly you want .

Thanks
Shephali SwarnkarShephali Swarnkar
Hi Dhruv,
       I want to get details of task (like subjects, assigned to,related to, etc...) but when i tried to access i got error 
"[Error] Error: List controllers are not supported for task"
<apex:page standardController="task" recordSetVar="tsk_list">
<apex:pageBlock title="list">
<apex:pageBlockTable value="{!tsk_list}" var="T">
</apex:pageBlockTable>
 </apex:pageBlock>  
</apex:page>

So now my question is how to access such details.
CongnizentCongnizent
Hi Shephali ,

Actually u can only use list controller (recordSetVar) for objects -
Account
Asset
Campaign
Case
Contact
Contract
Idea
Lead
Opportunity
Order
Product2
Solution
User
Custom objects

So you have to create a custom controller , then apply  a SOQL on task and show it on page . 

Let me know if you have further confusion .

Thanks

 
CongnizentCongnizent
Here is code for controller

public class repeatCon {

    public List<task> tasklist {get;set;
    }
    public repeatCon () {
    //Can add more field 
    tasklist =[Select Description,CallDisposition,CallDurationInSeconds from task ];
    }

}


and page 



<!-- Page: -->

<apex:page Controller="repeatCon ">

    <table border="0" >

        <tr>

            <th>Task Number</th><th>Origin</th>

            <th>Task Email</th><th>Status</th>

        </tr>

        <apex:repeat var="cases" value="{!tasklist }">

        <tr>

            <td>{!cases.Description}</td>

            <td>{!cases.CallDisposition}</td>

            <td>{!cases.CallDurationInSeconds }</td>


        </tr>

        </apex:repeat> 

    </table>

</apex:page>

If works then mark it best answer

Thank you 
Dhruv
Shephali SwarnkarShephali Swarnkar
Hi dhruv,
       Thanx for reply.its Working.
   I am trying retrieve "assigned to"  field name Owner(lookup field) but there is an error in it:
[Error] Error: tasklst Compile Error: only aggregate expressions use field aliasing at line 5 column 15
How to resolve this??
public class tasklst {

    public List<task> tasklist {get;set;}
    public tasklst() {
    tasklist =[Select subject,Priority, Owner status from task ];
    }

}
CongnizentCongnizent
Please try it ,


public class tasklst {

    public List<task> tasklist {get;set;}
    public tasklst() {
    tasklist =[Select subject,Priority, Owner, status from task ];
    }

}
 
Shephali SwarnkarShephali Swarnkar
Hi dhruv,
Error: tasklst Compile Error: No such column 'Owner' on entity 'Task'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. at line 5 column 15


public class tasklst {

    public List<task> tasklist {get;set;}
    public tasklst() {
    tasklist =[Select subject,Priority, status, ActivityDate,Owner from task ];
    }

}
CongnizentCongnizent
hmmm , this is my mistake actually , here we can not query owner as it's look up of Lookup(User,Calendar) . So you can try owner.Name if you want name of user .

So finally try it .  Hope it will work 


public class tasklst {

    public List<task> tasklist {get;set;}
    public tasklst() {
    tasklist =[Select subject,Priority, status, ActivityDate,Owner.Name from task ];
    }

}
 
This was selected as the best answer
Shephali SwarnkarShephali Swarnkar
Thanks to you dhruv.
One more Thing Dhruv How we Can Rename the fieds if i am showing the values as using page block and pageblocktable
"<apex:column value="{!o.Owner.Name}"/>" it shows the values With Column "Name" I want to rename as "AssignedTo".
Can we Do that??
CongnizentCongnizent
Hey shephali ,

Acutally there is no direct method for it as Select query not support aliasing . You can use apex:dataTable for it , or you can customize it using java script , or you can make a wrapper list in controller having coloumn 'asign to'. And how do u know my name is dhruv ?

 
CongnizentCongnizent
try it once .

<apex:facet name="header">Assigned to</apex:facet>

<apex:column value="{!o.Owner.Name}"/>

 
Shephali SwarnkarShephali Swarnkar
Hi Dhruv Gour(Got your name from mail you sent me.),
        No the facet will cover the whole column. and column for "Name" still showing there.
 
Shephali SwarnkarShephali Swarnkar
Solution is this:
<apex:column headerValue="Assigned To" value="{!o.Owner.Name}"/>
CongnizentCongnizent
ok got it .
thanks