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
XIOXIO 

Visualforce page that displays related Tasks to the Opportunity

Hello,

I'm trying to create a Visualforce page that only displays related Tasks that are of a certain type or status.This is what I have so far and I'm getting errors. Any assistance would be very much appreciated.

Extension:
public class AnnualTouchpointPlanningController {

    private List<Task> task;
    private Opportunity oppty; 
    public AnnualTouchpointPlanningController(ApexPages.StandardController controller) {
        this.oppty= (Opportunity)controller.getRecord();
    }
    public List<Task> getTask()
    {
       Opportunity opp = [Select id, Account.id FROM Opportunity where id = :oppty.id];
        if (opp.Account == null)
         return null;
        task = [Select id, Type, EarliestDate__c, DeadlineDate__c, ActualDate__c from Task where Account.id = :opp.Account.id];
        return task;
    }
}

Page:
<apex:page standardController="Opportunity" extensions="AnnualTouchpointPlanningController">
<style>
.fewerMore { display: none;}
</style>
<apex:form >
 <apex:pageMessages />
 <apex:detail relatedList="true"></apex:detail>
<apex:pageblock id="CustomList" title="Related Tasks"  >
   <apex:pageBlockTable value="{!task}" var="t" rendered="{!NOT(ISNULL(task))}">
        <apex:column value="{!t.EarliestDate__c}"/>
        <apex:column value="{!t.DeadlineDate__c}"/>
        <apex:column value="{!t.ActualDate__c}"/>
       <apex:column value="{!t.Type}"></apex:column>
       <apex:column value="{!t.Owner}"/>
   </apex:pageBlockTable>
   <apex:outputLabel value="No records to display" rendered="{!(ISNULL(task))}" styleClass="noRowsHeader"></apex:outputLabel>
 </apex:pageblock>
</apex:form>
</apex:page>



 
Best Answer chosen by XIO
XIOXIO
Final codes below:


Page:
<apex:page standardController="Opportunity" extensions="AnnualTouchpointPlanningController"  >
 <apex:form >
 <div align="center">
                 <apex:commandButton value="Save" action="{!save}" id="saveButton" />
</div>
 <apex:pageBlock id="pb">
<apex:pageMessages ></apex:pageMessages>


  <!--  <div align="center" draggable="false" >
 <apex:commandButton action="{!save}" value="Save" id="theButton"  /> </div> -->
  

    <apex:pageBlockTable value="{!TaskList}" var="d">
    
   
    
      <apex:column headerValue="Subject">   
                    <apex:outputField value="{!d.subject}">  
         <apex:inlineEditSupport event="ondblclick" 
            rendered="{!(d.subject!=NUll)&&
                      (d.subject!=Null) }"/>                      
</apex:outputField> </apex:column>


      
                 <apex:column headerValue="Type">   
                    <apex:outputField value="{!d.Type}">  
         <apex:inlineEditSupport event="ondblclick" 
            rendered="{!(d.Type!=NUll)&&
                      (d.Type!=Null) }"/>                      
</apex:outputField> </apex:column>
    
              <!--      <apex:column value="{!d.subject}" title="Subject"/>

                    <apex:column value="{!d.Type}" title="Type"/>   -->
                    
                    
                 <apex:column headerValue="Earliest Date">   
                    <apex:outputField value="{!d.EarliestDate__c}">  
         <apex:inlineEditSupport event="ondblclick" 
            rendered="{!(d.EarliestDate__c!=NUll)&&
                      (d.EarliestDate__c!=Null) }"/>                      
</apex:outputField> </apex:column>

            <!--        
                  <apex:column headerValue="Earliest Date">
                           <apex:outputText value="{0,date,MM/dd/yyyy}">
                            <apex:param value="{!d.EarliestDate__c}" />
                        </apex:outputText> 
                     </apex:column>  -->
                     
                     
                   <apex:column headerValue="Deadline Date">   
                    <apex:outputField value="{!d.ActivityDate}">  
         <apex:inlineEditSupport event="ondblclick" 
            rendered="{!(d.ActivityDate!=NUll) }"/>                      
             </apex:outputField> </apex:column>  
                     
                     
                    <apex:column headerValue="Actual Date">   
                    <apex:outputField value="{!d.ActualDate__c}">  
         <apex:inlineEditSupport event="ondblclick" 
            rendered="{!(d.ActualDate__c!=NUll) }"/>                      
             </apex:outputField> </apex:column>  
                     
              
                   
                    <apex:column title="Close">
                    
                    <apex:commandLink value="Close" action="{!deleteCon}" reRender="pb"  oncomplete="window.top.location = '/{!Opportunity.id}';">
                   <apex:param value="{!d.id}" assignTo="{!dcid}" name="dtlIdParam"/>
             </apex:commandLink>
                    
                    </apex:column>
                   
        <apex:inlineEditSupport event="ondblClick" 
                        showOnEdit="saveButton,cancelButton" hideOnEdit="editButton" /> 
          
          
 </apex:pageBlockTable>
 
 <!-- <apex:pageBlockButtons > 
                
                <apex:commandButton value="Save" action="{!save}" id="saveButton" />
            </apex:pageBlockButtons>  -->
  
 </apex:pageblock>
</apex:form>
</apex:page>

Controller:
public class AnnualTouchpointPlanningController {

    Public List<Task> TaskList{get;set;}
    public String contId{get;set;} 
    public String dcid{get;set;}
    public task task{get;set;}
    Public string editid{get;set;} 
    public opportunity oo;
        public Id selectedDetailID { get;set; }

    
    String currentRecordId ; 
    public AnnualTouchpointPlanningController(ApexPages.StandardController controller) {
       // this.oppty= (Opportunity)controller.getRecord();
        
        currentRecordId  = ApexPages.CurrentPage().getparameters().get('id');
       
     TaskList = [Select subject,id, Type, EarliestDate__c, DeadlineDate__c, ActualDate__c, Who.Type,whatID,priority,status,ActivityDate,ATP_Task__c FROM Task WHERE Whatid=:currentRecordId and ATP_Task__c=true ];
     
    
     
     if(TaskList.size() == 0)
{
    Apexpages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,''+'No ATP Tasks to Display'));
   } 
 }
 
 public pagereference saveProject(){
 

  system.debug('ssssss'+TaskList );
    
    upsert TaskList ; // the LIST
  
     PageReference pageRef = new PageReference('/apex/AnnualTouchpointPlanning');
    pageRef.setRedirect(true);
    return null;
}    
     
    public PageReference save()
    {
        upsert TaskList ;
        
        return new PageReference('/apex/AnnualTouchpointPlanning');
    }  
     
     
       public pagereference deleteCon() {
       String s1 = System.CurrentPageReference().getParameters().get('dtlIdParam');
       task t=[ select id,ActualDate__c,status From task Where id=:s1];
       t.ActualDate__c=system.today();
       t.status= 'completed';
       upsert t;
       PageReference pageRef = new PageReference('/apex/AnnualTouchpointPlanning');
       pageRef.setRedirect(true);
       return null;
   } 
    
 
   
   
}

 

All Answers

Nishad KNishad K
Hi Harmens,

Try the below class instead yours, let me know the outcomes   
 
public class AnnualTouchpointPlanningController {

    public List<Task> task {get;set};
    private Opportunity oppty; 
    public AnnualTouchpointPlanningController(ApexPages.StandardController controller) {
        this.oppty= (Opportunity)controller.getRecord();
        getTaskDetails();
    }
    public void getTaskDetails()
    {
       Opportunity opp = [Select id, Account.id FROM Opportunity where id = :oppty.id];
        task = [Select id, Type, EarliestDate__c, DeadlineDate__c, ActualDate__c from Task where Account.id = :opp.Account.id];
    }
}
Regards,

 
XIOXIO
Hi Nishad,

Thank you for the help! I changed line 3 on your code to get rid of an error but now I'm getting this error:

Error: Compile Error: The method List<Task> getTask() is referenced by Visualforce Page (AnnualTouchpointPlanning) in salesforce.com. Remove the usage and try again. at line 8 column 23

Updated Extension:
public class AnnualTouchpointPlanningController {

    public List<Task> task {get;set;}
    private Opportunity oppty; 
    public AnnualTouchpointPlanningController(ApexPages.StandardController controller) {
        this.oppty= (Opportunity)controller.getRecord();
        getTaskDetails();
    }
    public void getTaskDetails()
    {
       Opportunity opp = [Select id, Account.id FROM Opportunity where id = :oppty.id];
        task = [Select id, Type, EarliestDate__c, DeadlineDate__c, ActualDate__c from Task where Account.id = :opp.Account.id];
    }
}

 
XIOXIO
Hello, I was able to save with no errors but now I get his error when the page is trying to display: 

Content cannot be displayed: Too many query rows: 50001
Nishad KNishad K
Hi Harmens,

Be aware that the 50k limit is an overall per-transaction limit, and not a per-query limit. Do you have other code in your test method that makes SOQL queries? Are there at least 4 other queries with LIMIT 10000 in them? If so, that would do it. That things fail only in production, where you have more data, hints that this could be the case.

Also, since you mentioned that this is a test method: if any of the queries contributing to this are in logic to set up your test you may be able to use Test.startTest and Test.stopTest to help. Code that is run between these two methods gets a new set of limits, which means that in a scenario where exactly half your work is setup/teardown you can query 100k records instead.

Regards,
Amit Singh 1Amit Singh 1
Hi Harmen,

You are only showing List of Task that is related to a Particular Account and not performing Any DML operation. right?

If this is the scenario, make readOnly attribute of VF page to true 
readOnly="true"
And show your data without using page block table or Apex Repeat you can show Task records up to 100k into VF page. VF is limited to show 1000 records if any DML is being performed and if you make read-only attribute to true then inside Page Block Table OR Apex Repeat you can only show 10K records this is the reason I mentioned not to use data into Page Block Table you can apply some css for look and feel.

Let me know if this helps :)

Thanks,
Amit Singh.

 
XIOXIO
Thank you all for the help! The VF page needs to be editable. Basically, a related list of Tasks on Opportunity that are a certain Task Type wether they are open or closed. 
Amit Singh 1Amit Singh 1
Hi Harmen,

Then Pagination will be the best option for you OR you can use VF remoting but I am not sure if VF Remoting will resolve the issue.

Thanks,
Amit Singh.
XIOXIO
Final codes below:


Page:
<apex:page standardController="Opportunity" extensions="AnnualTouchpointPlanningController"  >
 <apex:form >
 <div align="center">
                 <apex:commandButton value="Save" action="{!save}" id="saveButton" />
</div>
 <apex:pageBlock id="pb">
<apex:pageMessages ></apex:pageMessages>


  <!--  <div align="center" draggable="false" >
 <apex:commandButton action="{!save}" value="Save" id="theButton"  /> </div> -->
  

    <apex:pageBlockTable value="{!TaskList}" var="d">
    
   
    
      <apex:column headerValue="Subject">   
                    <apex:outputField value="{!d.subject}">  
         <apex:inlineEditSupport event="ondblclick" 
            rendered="{!(d.subject!=NUll)&&
                      (d.subject!=Null) }"/>                      
</apex:outputField> </apex:column>


      
                 <apex:column headerValue="Type">   
                    <apex:outputField value="{!d.Type}">  
         <apex:inlineEditSupport event="ondblclick" 
            rendered="{!(d.Type!=NUll)&&
                      (d.Type!=Null) }"/>                      
</apex:outputField> </apex:column>
    
              <!--      <apex:column value="{!d.subject}" title="Subject"/>

                    <apex:column value="{!d.Type}" title="Type"/>   -->
                    
                    
                 <apex:column headerValue="Earliest Date">   
                    <apex:outputField value="{!d.EarliestDate__c}">  
         <apex:inlineEditSupport event="ondblclick" 
            rendered="{!(d.EarliestDate__c!=NUll)&&
                      (d.EarliestDate__c!=Null) }"/>                      
</apex:outputField> </apex:column>

            <!--        
                  <apex:column headerValue="Earliest Date">
                           <apex:outputText value="{0,date,MM/dd/yyyy}">
                            <apex:param value="{!d.EarliestDate__c}" />
                        </apex:outputText> 
                     </apex:column>  -->
                     
                     
                   <apex:column headerValue="Deadline Date">   
                    <apex:outputField value="{!d.ActivityDate}">  
         <apex:inlineEditSupport event="ondblclick" 
            rendered="{!(d.ActivityDate!=NUll) }"/>                      
             </apex:outputField> </apex:column>  
                     
                     
                    <apex:column headerValue="Actual Date">   
                    <apex:outputField value="{!d.ActualDate__c}">  
         <apex:inlineEditSupport event="ondblclick" 
            rendered="{!(d.ActualDate__c!=NUll) }"/>                      
             </apex:outputField> </apex:column>  
                     
              
                   
                    <apex:column title="Close">
                    
                    <apex:commandLink value="Close" action="{!deleteCon}" reRender="pb"  oncomplete="window.top.location = '/{!Opportunity.id}';">
                   <apex:param value="{!d.id}" assignTo="{!dcid}" name="dtlIdParam"/>
             </apex:commandLink>
                    
                    </apex:column>
                   
        <apex:inlineEditSupport event="ondblClick" 
                        showOnEdit="saveButton,cancelButton" hideOnEdit="editButton" /> 
          
          
 </apex:pageBlockTable>
 
 <!-- <apex:pageBlockButtons > 
                
                <apex:commandButton value="Save" action="{!save}" id="saveButton" />
            </apex:pageBlockButtons>  -->
  
 </apex:pageblock>
</apex:form>
</apex:page>

Controller:
public class AnnualTouchpointPlanningController {

    Public List<Task> TaskList{get;set;}
    public String contId{get;set;} 
    public String dcid{get;set;}
    public task task{get;set;}
    Public string editid{get;set;} 
    public opportunity oo;
        public Id selectedDetailID { get;set; }

    
    String currentRecordId ; 
    public AnnualTouchpointPlanningController(ApexPages.StandardController controller) {
       // this.oppty= (Opportunity)controller.getRecord();
        
        currentRecordId  = ApexPages.CurrentPage().getparameters().get('id');
       
     TaskList = [Select subject,id, Type, EarliestDate__c, DeadlineDate__c, ActualDate__c, Who.Type,whatID,priority,status,ActivityDate,ATP_Task__c FROM Task WHERE Whatid=:currentRecordId and ATP_Task__c=true ];
     
    
     
     if(TaskList.size() == 0)
{
    Apexpages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,''+'No ATP Tasks to Display'));
   } 
 }
 
 public pagereference saveProject(){
 

  system.debug('ssssss'+TaskList );
    
    upsert TaskList ; // the LIST
  
     PageReference pageRef = new PageReference('/apex/AnnualTouchpointPlanning');
    pageRef.setRedirect(true);
    return null;
}    
     
    public PageReference save()
    {
        upsert TaskList ;
        
        return new PageReference('/apex/AnnualTouchpointPlanning');
    }  
     
     
       public pagereference deleteCon() {
       String s1 = System.CurrentPageReference().getParameters().get('dtlIdParam');
       task t=[ select id,ActualDate__c,status From task Where id=:s1];
       t.ActualDate__c=system.today();
       t.status= 'completed';
       upsert t;
       PageReference pageRef = new PageReference('/apex/AnnualTouchpointPlanning');
       pageRef.setRedirect(true);
       return null;
   } 
    
 
   
   
}

 
This was selected as the best answer