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
Aditya Rayavarapu 5Aditya Rayavarapu 5 

Attach Open Activities to Case

Hi, I created a VF page where we can search for a case using the case number. 

However, in the result, I also want to display the Open Activites related to the Case.
I am able to reference the Case object fields in the page, but cannot figure out how to do that with the Open Activites fields (Status, Priority, Subject)

Controller:

public class casesearchcontroller {
     public list <case> cas {get;set;}
    public casesearchcontroller(ApexPages.StandardController controller) {
    
    }
    
   public string searchstring {get;set;}  
    
   public void search(){  
     string searchquery='select casenumber,Email__c,Category__c,SubCategory__c,(Select  ActivityDate, Status, Priority,Subject FROM OpenActivities)from case where CaseNumber like \'%'+searchstring+'%\' Limit 30';  
     cas= Database.query(searchquery);  
   }  
   public void clear(){  
   cas.clear();  
   }  
 }


Page:

<apex:page standardController="Case" extensions="caseextension" showheader="false" >
 <apex:form >  
 <apex:inputText value="{!searchstring}" label="Input"/>   
  <apex:commandButton value="Find Case" action="{!search}"/>  
  <apex:commandButton value="Clear Search" action="{!search}"/>  
   <apex:pageBlock title="Search Result">  
    <apex:pageblockTable value="{!cas}" var="c">  
      
     <apex:column value="{!c.CaseNumber}"/>  
     <apex:column value="{!c.Email__c}"/>
      <apex:column value="{!c.Category__c}"/>
    <apex:column value="{!c.SubCategory__c}"/>
    
     
    </apex:pageblocktable>
          </apex:pageBlock> 
     </apex:form> 
</apex:page>

Any help?

Thanks!

ShashankShashank (Salesforce Developers) 
Since there can be more than 1 open activities in a case, I would recommend you to add one more pageblocktable which shows open activities separately, since anyway there will only be 1 case with the casenumber.
Aditya Rayavarapu 5Aditya Rayavarapu 5
How would I add the activity values in the page? Like if it was a case field, I used "{!c.Email__c}". What would I use for activity status for example?
ShashankShashank (Salesforce Developers) 
You should create a separate pageblocktable for activities, which you can probably show separate from the case pageblocktable. in your search() method in the controller, you can store the activity list in another list property and pass it to the page.

something like

list<task> tasklist = cas.openactivities;