Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

First, I'm a complete noob and this is my first attempt at a Visual Force page. So, I've created a simple Datatable that lists out Tasks that are related to only a certain group of Contacts that are related to an Account.

I've got that Datatable working just fine, I just need to know how to make it so that I can insert the datatable on the Account page itself. (Also so that the apex portion can grab the account ID).

I've tried extending to "Account" but it fails in the VF and I'm just not sure how exactly to relate the Account Object to my Controller so that I can see it in the Layout and add it to the Account page. I could use some advice here. Please and thank you :)

Here's the View:

<apex:page controller="listPractice" tabstyle="account">
<style>
    .activeTab {
        background-color: #236FBD;
        color:white;
        .background-image:none;
    }

    .inactiveTab {
        background-color:lightgrey;
        color:black;
        background-image:none;
    }
</style>
 <!--SHOWING LIMITED-->
 <apex:pageBlock title="Open Activities for {!account.name} Staff">
     <apex:tabPanel switchType="client" selectedTab="tabOpenActivities" tabclass="activeTab" inactiveTabClass="inactiveTab">
     <!--Open Tasks-->
    <apex:tab label="Open Activities" name="openActivities" id="tabOpenActivities">
    <apex:dataTable value="{!tasksLimited}" var="taskLimited" cellpadding="4" bgcolor="white" rowClasses="even,odd">
        <apex:column headerValue="Subject"><apex:outputLink value="/{!URLFOR(taskLimited['id'])}">{!taskLimited.subject}</apex:outputLink></apex:column>
         <apex:column value="{!taskLimited.whoid}" headerValue="Staff"/>
         <apex:column value="{!taskLimited.type}" headerValue="Type"/>
         <apex:column value="{!taskLimited.accountid}" headerValue="School"/>
         <apex:column value="{!taskLimited.activitydate}" headerValue="Due Date"/>
         <apex:column value="{!taskLimited.status}" headerValue="Status"/>
         <apex:column value="{!taskLimited.priority}" headerValue="Priority"/>
         <apex:column value="{!taskLimited.ownerid}" headerValue="Assigned To"/>
     </apex:dataTable>

     </apex:tab>

     <!--Closed Tasks-->
    <apex:tab label="Closed Activities" name="closedActivities" id="tabClosedActivities">
     <apex:dataTable value="{!closedTasksLimited}" var="closedTaskLimited" cellpadding="4" bgcolor="white" rowClasses="even,odd">
         <apex:column headerValue="Subject"><apex:outputLink value="/{!URLFOR(closedTaskLimited['id'])}">{!closedTaskLimited.subject}</apex:outputLink></apex:column>
         <apex:column value="{!closedTaskLimited.whoid}" headerValue="Staff"/>
         <apex:column value="{!closedTaskLimited.type}" headerValue="Type"/>
         <apex:column value="{!closedTaskLimited.accountid}" headerValue="School"/>
         <apex:column value="{!closedTaskLimited.activitydate}" headerValue="Due Date"/>
         <apex:column value="{!closedTaskLimited.status}" headerValue="Status"/>
         <apex:column value="{!closedTaskLimited.priority}" headerValue="Priority"/>
         <apex:column value="{!closedTaskLimited.ownerid}" headerValue="Assigned To"/>
     </apex:dataTable>
     </apex:tab>
 </apex:tabPanel>
 <apex:outputLink value="/apex/staffContactTaskListFull?id={!account.id}">Full Results Listing</apex:outputLink><br/>
 </apex:pageBlock>

Here's the Controller:

public class listPractice {


//Get Only Staff Contacts
List<Contact> cons=[SELECT id FROM Contact WHERE AccountId=:System.currentPageReference().getParameters().get('id') AND RecordTypeId='012d0000000XECqAAO'];


List<Task> tasks=new List<Task>();
List<Task> closedTasks=new List<Task>();
List<Task> tasksLimited=new List<Task>();
List<Task> closedTasksLimited=new List<Task>();


//Get the School Account Information
public Account getAccount() {
    return [SELECT id, name FROM Account WHERE Id=:System.currentPageReference().getParameters().get('id')];
}

//Get Open Tasks for School Staff
public List<Task> getTasks() {

    tasks= [SELECT id, whoid, description, subject, type, type_reporting__c, whatid, activitydate, ownerid, status, priority, accountid FROM task WHERE WhoId in :cons AND IsClosed=false ORDER BY activitydate DESC];
    return tasks;
}

//Get Closed Tasks for School Staff
public List<Task> getClosedTasks() {

    closedTasks= [SELECT id, whoid, description, subject, type, type_reporting__c, whatid, activitydate, ownerid, status, priority, accountid FROM task WHERE WhoId in :cons AND IsClosed=true ORDER BY activitydate DESC];
    return closedTasks;
}

//Get Open Tasks for School Staff LIMIT 10
public List<Task> getTasksLimited() {

    tasksLimited= [SELECT id, whoid, description, subject, type, type_reporting__c, whatid, activitydate, ownerid, status, priority, accountid FROM task WHERE WhoId in :cons AND IsClosed=false ORDER BY activitydate DESC LIMIT 10];
    return tasksLimited;
}

//Get Closed Tasks for School Staff LIMIT 10
public List<Task> getClosedTasksLimited() {

    closedTasksLimited= [SELECT id, whoid, description, subject, type, type_reporting__c, whatid, activitydate, ownerid, status, priority, accountid FROM task WHERE WhoId in :cons AND IsClosed=true ORDER BY activitydate DESC LIMIT 10];
    return closedTasksLimited;
}
}
share|improve this question

2 Answers 2

up vote 3 down vote accepted

If I am not wrong your requirement is to add your Visualforce page in Account page layout section. If that is your requirement you have to add your page in page layout but for that you have to do some modifications in code in class and as well as on page. Here is the code snippet that I have modified.

For class:

public with sharing class listPractice {

public Account acc {get;set;}
public List<Task> tasks {get;set;}
public List<Task> closedTasks {get;set;}
public List<Task> tasksLimited {get;set;}
public List<Task> closedTasksLimited {get;set;}

public List<Contact> cons {get;set;}

public listPractice(ApexPages.StandardController con){
    acc = (Account) con.getRecord();
    //Get Only Staff Contacts
    cons=[SELECT id FROM Contact WHERE AccountId=: acc.Id];


    tasks=new List<Task>();
    closedTasks=new List<Task>();
    tasksLimited=new List<Task>();
    closedTasksLimited=new List<Task>();
}




//Get the School Account Information
public Account getAccount() {
    return [SELECT id, name FROM Account WHERE Id=: acc.Id];
}

//Get Open Tasks for School Staff
public List<Task> getTasks() {

    tasks= [SELECT id, whoid, description, subject, type, whatid, activitydate, ownerid, status, priority, accountid FROM task WHERE WhoId in :cons AND IsClosed=false ORDER BY activitydate DESC];
    return tasks;
}

//Get Closed Tasks for School Staff
public List<Task> getClosedTasks() {

    closedTasks= [SELECT id, whoid, description, subject, type, whatid, activitydate, ownerid, status, priority, accountid FROM task WHERE WhoId in :cons AND IsClosed=true ORDER BY activitydate DESC];
    return closedTasks;
}

//Get Open Tasks for School Staff LIMIT 10
public List<Task> getTasksLimited() {

    tasksLimited= [SELECT id, whoid, description, subject, type, whatid, activitydate, ownerid, status, priority, accountid FROM task WHERE WhoId in :cons AND IsClosed=false ORDER BY activitydate DESC LIMIT 10];
    return tasksLimited;
}

//Get Closed Tasks for School Staff LIMIT 10
public List<Task> getClosedTasksLimited() {

    closedTasksLimited= [SELECT id, whoid, description, subject, type, whatid, activitydate, ownerid, status, priority, accountid FROM task WHERE WhoId in :cons AND IsClosed=true ORDER BY activitydate DESC LIMIT 10];
    return closedTasksLimited;
}
}

And for Visualforce page:

<apex:page standardController="Account" extensions="listPractice" tabstyle="account">
<style>
.activeTab {
    background-color: #236FBD;
    color:white;
    .background-image:none;
}

.inactiveTab {
    background-color:lightgrey;  
    color:black;
    background-image:none;
}
</style>
 <!--SHOWING LIMITED-->
 <apex:pageBlock title="Open Activities for {!account.name} Staff">
     <apex:tabPanel switchType="client" selectedTab="tabOpenActivities" tabclass="activeTab" inactiveTabClass="inactiveTab">

 <!--Open Tasks-->
<apex:tab label="Open Activities" name="openActivities" id="tabOpenActivities">
<apex:dataTable value="{!tasksLimited}" var="taskLimited" cellpadding="4" bgcolor="white" rowClasses="even,odd">
    <apex:column headerValue="Subject"><apex:outputLink value="/{!URLFOR(taskLimited['id'])}">{!taskLimited.subject}</apex:outputLink></apex:column>
     <apex:column value="{!taskLimited.whoid}" headerValue="Staff"/>
     <apex:column value="{!taskLimited.type}" headerValue="Type"/>
     <apex:column value="{!taskLimited.accountid}" headerValue="School"/>
     <apex:column value="{!taskLimited.activitydate}" headerValue="Due Date"/>
     <apex:column value="{!taskLimited.status}" headerValue="Status"/>
     <apex:column value="{!taskLimited.priority}" headerValue="Priority"/>
     <apex:column value="{!taskLimited.ownerid}" headerValue="Assigned To"/>
 </apex:dataTable>

 </apex:tab>

 <!--Closed Tasks-->
<apex:tab label="Closed Activities" name="closedActivities" id="tabClosedActivities">
 <apex:dataTable value="{!closedTasksLimited}" var="closedTaskLimited" cellpadding="4" bgcolor="white" rowClasses="even,odd">
     <apex:column headerValue="Subject"><apex:outputLink value="/{!URLFOR(closedTaskLimited['id'])}">{!closedTaskLimited.subject}</apex:outputLink></apex:column>
     <apex:column value="{!closedTaskLimited.whoid}" headerValue="Staff"/>
     <apex:column value="{!closedTaskLimited.type}" headerValue="Type"/>
     <apex:column value="{!closedTaskLimited.accountid}" headerValue="School"/>
     <apex:column value="{!closedTaskLimited.activitydate}" headerValue="Due Date"/>
     <apex:column value="{!closedTaskLimited.status}" headerValue="Status"/>
     <apex:column value="{!closedTaskLimited.priority}" headerValue="Priority"/>
     <apex:column value="{!closedTaskLimited.ownerid}" headerValue="Assigned To"/>
 </apex:dataTable>
 </apex:tab>

Full Results Listing

Now goto Account edit page layout, select component and then add your Visualforce page in a section, save the page layout and see the output on Account page.

I hope this answers your question.

share|improve this answer
    
ok this is valuable to my learning! So I should wrap the collections in a method that extends the Contact object, and then using get;set; allows me to not have to pull the ID from the URL?? I'm sorry for more questions, I'm really just trying to understand it. As I understand from reading salesforce.com/us/developer/docs/apexcode/Content/… the get;set; are constructors that pull the relevant properties from the page where the controller lives? –  mikesalty Jul 7 at 15:25
    
Ok... In the above code there are two things which you need to concentrate on visualforce page i.e. first one is StandardController and Extensions. Whenever you define StandardController you can use only Extensions and in StandardController you can only define Standard objects. Now when you define standardobject on page you can get the data in extension using Apexpages.StandardController in the controller, in our case acc will contain the Account data and from there you will get the account id. get;set; are the getter and setter for the properties which will get or set the properties. –  tandonprateek Jul 7 at 16:38

You'd be better off starting with Accounts and making your data table a related list. Your problem is that Tasks and Contacts can be related to Accounts. What you don't have shown in your controller is a way of relating either of them back to Account.ID.

Unless the WhatID of the Task is the Account.ID, then you don't have what you need. Most likely that would be the way to get the Account.ID. So, if you want to select the Accounts based on the WhatID of the Tasks, then that would probably be the "best" way to do it. If the WhatID is related to the Contact (doesn't appear to be as that would normally be the WhoID which you're using), then you could also do it that way. We don't know and can't tell from looking at your code.

Hope this helps point you in the right direction.

share|improve this answer
    
whoid is the contact, and whatid is the account. The code that I have is actually working, it selects only the contacts of a certain record type that are related to the account, the account ID I'm pulling from the URL. But that's not the trouble I'm having, I'm simply having trouble getting it onto the Account page layout, and all the advice I can see tells me to add extends="Account" in visualforce but that's not working. –  mikesalty Jul 7 at 14:20
    
Your code as written wouldn't extend Accounts. You'd need to rewrite it in order for it to do that. Reason being, you don't do your queries based on Accounts or pass in the Account ID to get the related Tasks or Contacts. If you add a getter and setter, then you'd be able to do that. See the VF Workbooks for more on that. –  crmprogdev Jul 7 at 14:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.