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
Iridious JonesIridious Jones 

How to create a history of cases created by a user

Hello Everyone,

I'm attempting to create a VF page/component that will give me a case history so to speak. When a user creates a case I'd like a history of cases created by that user for any record type to appear in a case history list. Any ideas on how I can acheive this. I'm completely new to SF and Apex.
Best Answer chosen by Iridious Jones
Rangeshwara KonaRangeshwara Kona
Hi 

Step #1: 
Create a new formula field "Created User Id" like below 


 User-added image


Step #2:

Create a report with filter value of Created User Id and make sure you save the report

User-added image



Report filter values can be passed via URL like below
https://na14.salesforce.com/<report_id>?pv0=<paramter_value>

pass your report id for <report_id>
pass created user id for <paramter_value>

https://na14.salesforce.com/00Od0000005eesE?pv0=005d00000013aZC


Step #3:

Create formula field in Case object like below 

User-added image



Step #4:

Add newly created field onto Case Page layout


Now: whenever user clicks on the link system automatically runs the report where it shows the history or cases created by that specific user 


Hope this helps.

Thanks,
Rangesh








 

All Answers

Rangeshwara KonaRangeshwara Kona
Hi 

Step #1: 
Create a new formula field "Created User Id" like below 


 User-added image


Step #2:

Create a report with filter value of Created User Id and make sure you save the report

User-added image



Report filter values can be passed via URL like below
https://na14.salesforce.com/<report_id>?pv0=<paramter_value>

pass your report id for <report_id>
pass created user id for <paramter_value>

https://na14.salesforce.com/00Od0000005eesE?pv0=005d00000013aZC


Step #3:

Create formula field in Case object like below 

User-added image



Step #4:

Add newly created field onto Case Page layout


Now: whenever user clicks on the link system automatically runs the report where it shows the history or cases created by that specific user 


Hope this helps.

Thanks,
Rangesh








 
This was selected as the best answer
Iridious JonesIridious Jones
Thank you Rangeshwara. I'll give this a run today.
Iridious JonesIridious Jones
This worked great. The next part of this is to pass the report and the parameter to a VF page to be displayed.
 
Iridious JonesIridious Jones
It gave me an excellent report however when I drop the report in a VF page and add that page to the case it automatically loads and takes the user to the report page leaving from the case. How can I get this to appear as a section on the case page without leaving the case.
 
Rangeshwara KonaRangeshwara Kona
Hi Iridious,

Solution I provided is using declartive power of salesforce. If you want to display user case creation history in Case page layout then you should take inline VF Page approach.

Step #1: Create Apex Controller
Step #2: Create VF Page using standard controller as case and extension controller as the one you created in Step #1
Step #3: Edit Case Page Layout a) create new section b) go to Visualforce Pages and select VF Page you created in Step #2 to add it to section 

Step #1 Code
 
public class UserCaseListController{ 

    // declare Case List objects
    public List<Case> UserCaseList {get; set;} 
    public List<Case> UserCaseId {get; set;} 

    // declare UserId String 
    public String UserId{get;set;}

    // define standardcontroller variable
    private ApexPages.StandardController controller {get; set;}
    // the actual account
    
    // define case object variable
    private Case a;
  
    // instantiate controller
    public UserCaseListController(ApexPages.StandardController controller) {

        //initialize the stanrdard controller
        this.controller = controller;
        
        // retrieve page record id
        this.a = (Case)controller.getRecord();
        
        // execute case list block 
        this.show();
    }
    
    
    // Gather user case history details
    
    public PageReference show() {
        if (UserCaseList== null) {
           UserCaseList = new List<case>(); // init the list if it is null
        } else {
            UserCaseList.clear(); // clear out the current results if they exist
        }
    
       // retrieve case user id and use that id to query for  user created case  records 
       UserCaseId   = [select CreatedById from Case where Id = :a.Id  ];
       
       UserCaseList = [select CaseNumber, Subject, Description, CreatedById, Status, CreatedDate from Case where CreatedById = :UserCaseId[0].CreatedById  Order by CreatedDate desc];
       
        return null;
    }
    
}

Step #2 Code :
 
<apex:page standardController="Case" extensions="UserCaseListController"> 
  <apex:pageBlock >
     <apex:pageBlockSection id="resultsBlock" columns="1">
                <apex:pageBlockTable value="{!UserCaseList}" var="o" rendered="{!NOT(ISNULL(UserCaseList))}">
                    <apex:column value="{!o.CaseNumber}"/>
                    <apex:column value="{!o.Subject}"/>
                    <apex:column value="{!o.Description}"/>
                    <apex:column value="{!o.Status}"/>
                    <apex:column value="{!o.CreatedDate}"/>
                    <apex:column value="{!o.CreatedById}"/>
                </apex:pageBlockTable>
            </apex:pageBlockSection>   
   </apex:pageBlock>
</apex:page>

Step #3

User-added image



Final Look:

User-added image
 
Iridious JonesIridious Jones
I have one more question- Can the query "UserCaseList = [select CaseNumber, Subject, Description, CreatedById, Status, CreatedDate from Case where CreatedById = :UserCaseId[0].CreatedById  Order by CreatedDate desc];"

Can we make the FROM clause a report and the condition an record type.
Iridious JonesIridious Jones
By the way thank you I really appreciate your help on this. 
Iridious JonesIridious Jones
Would that look like 
​UserCaseList = [select CaseNumber, Subject, Description, CreatedById, Status, CreatedDate from Case where CreatedById = :UserCaseId[0].CreatedById  AND CaseRecordType = :IT Order by CreatedDate desc];
Rangeshwara KonaRangeshwara Kona
UserCaseList = [select CaseNumber, Subject, Description, CreatedById, Status, CreatedDate from Case where CreatedById = :UserCaseId[0].CreatedById AND CaseRecordType = 'specify_Record_type_here' Order by CreatedDate desc];



above query should help