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
shobana shobanashobana shobana 

Showing open tasks and open event of lead object in two separate section in pagelayout

Hi everyone,

I am new bie to Salesforce.
This is my first controller  and visualforce page.

This is my scenario....
I would like to show open task as seperate section on my lead page layout.
For that i took a standard controller with extension but its not showing the records but am not getting any error .Actually when i put that query in query editor its showing task  record of lead .
public class te {
    public List<OpenActivity> open{get;set;}
    public Lead ld;
    public te(ApexPages.StandardController controller) {
    
     ld=(Lead)controller.getrecord();
   
    }
public List<OpenActivity> getopen()
        {
               
            SObject[] c =[SELECT Name, 
                 (Select Id,Subject,IsTask, WhoId, WhatId,  ActivityDate,
                  Status, Priority, OwnerId FROM OpenActivities
                  where IsTask=True  
                  ) 
                  From Lead];
                      
  
        return  open;       
        } 

}


Visualforce page

<apex:page standardController="Lead" extensions="te">
<apex:pageBlock >
<apex:dataTable value="{!open}" var="each"  styleclass="list" >
<apex:column headerValue="Subject">{!each.Subject}</apex:column>
<apex:column headerValue="Name">{!each.WhoId}</apex:column>
<apex:column headerValue="Status">{!each.Status}</apex:column>
</apex:dataTable>
</apex:pageBlock>
</apex:page>
Can anyone please help me out.
Thank you in advance.
Best Answer chosen by shobana shobana
Bhanu MaheshBhanu Mahesh
Hi Shobana,

try this

Extension:
public class te {
    public List<OpenActivity> open{get;set;}
    public Id leadld;
    public te(ApexPages.StandardController controller) {
        leadld = ApexPages.CurrentPage().getparameters().get('id');
        List<Lead> c =[SELECT Name, 
                                  (Select Id,Subject,IsTask, WhoId, ActivityDate,
                                    Status, Priority, OwnerId FROM OpenActivities WHERE IsTask=True) 
                            FROM Lead WHERE Id = :leadld];
        if(c.size() > 0){
            open = c[0].OpenActivities;
        }
    }
}

Page;
<apex:page standardController="Lead" extensions="te">
    <apex:pageBlock >
    <apex:dataTable value="{!open}" var="each"  styleclass="list" >
        <apex:column headerValue="Subject">{!each.Subject}</apex:column>
        <apex:column headerValue="Name">{!Lead.Name}</apex:column>
        <apex:column headerValue="Status">{!each.Status}</apex:column>
    </apex:dataTable>
    </apex:pageBlock>
</apex:page>

Add this page in the Lead Page layout to display the records

Regards,
Bhanu Mahesh

All Answers

Bhanu MaheshBhanu Mahesh
Hi Shobana,

try this

Extension:
public class te {
    public List<OpenActivity> open{get;set;}
    public Id leadld;
    public te(ApexPages.StandardController controller) {
        leadld = ApexPages.CurrentPage().getparameters().get('id');
        List<Lead> c =[SELECT Name, 
                                  (Select Id,Subject,IsTask, WhoId, ActivityDate,
                                    Status, Priority, OwnerId FROM OpenActivities WHERE IsTask=True) 
                            FROM Lead WHERE Id = :leadld];
        if(c.size() > 0){
            open = c[0].OpenActivities;
        }
    }
}

Page;
<apex:page standardController="Lead" extensions="te">
    <apex:pageBlock >
    <apex:dataTable value="{!open}" var="each"  styleclass="list" >
        <apex:column headerValue="Subject">{!each.Subject}</apex:column>
        <apex:column headerValue="Name">{!Lead.Name}</apex:column>
        <apex:column headerValue="Status">{!each.Status}</apex:column>
    </apex:dataTable>
    </apex:pageBlock>
</apex:page>

Add this page in the Lead Page layout to display the records

Regards,
Bhanu Mahesh
This was selected as the best answer
shobana shobanashobana shobana
Thank you its working