Setup

The hands-on training is based on the default developer edition organization and has some customizations that must be done prior to starting with the rest of the exercises

  1. Sign up for a new Developer Edition
  2. Change the priority field on the case to only have High and Normal
    1. Click Setup | Customize | Cases | Fields
    2. Click Priority
    3. Ciick Edit next to Low
    4. Check Make this value the default for the master picklist
    5. Click Save
    6. Click Del next to Medium
  3. Create a new Owner Comment Count field
    1. Click Setup | Customize | Cases | Fields
    2. Click New under Case Custom Fields & Relationships
    3. Choose Number and click Next
    4. Fill in the following information
      Field Label
      Owner Comment Count
      Length
      18
      Decimal Places
      0
      Field Name
      Owner_Comment_Count
    5. Click Next
    6. Click Next
    7. Click Save
  4. Remove all page layouts for Case except Case Layout
    1. Click Setup | Customize | Cases | Page Layouts
    2. Click Del next to Case (Marketing) Layout
    3. Click Replace
    4. Repeat B-C for Case (Sales) Layout
    5. Repeat B-C for Case (Support) Layout
  5. Add Business Hours to the case layout
    1. Click Setup | Customize | Cases | Page Layouts
    2. Click Edit next to Case Layout
    3. Drag the Business Hours field onto the page layout
    4. Click Save
  6. Add a new breach email template
    1. Click Setup | Communication Templates | Email Templates
    2. Click New Template
    3. Choose Text
    4. Click Next
    5. Fill in the following information
      Folder
      Unfiled Public Email Templates
      Template Name
      Support: Case has breached
      Unique Name
      Support_Case_has_breached
      Subject
      Case {!Case.CaseNumber} has breached SLA
      Body
      Case Number: {!Case.CaseNumber}
      Subject: {!Case.Subject}
    6. Click Save
  7. Create the CaseCommentCount trigger
    1. Click Setup | Develop | Apex Triggers
    2. Click Developer Console
    3. Click File | New | Apex Trigger
    4. Fill in the following information and click Submit
      Name
      CaseCommentCount
      sObject
      Case
    5. Replace the contents with the following
      trigger CaseCommentCount on CaseComment (after insert, after delete) {
      	Set<Id> ownerIds = new Set<Id>();
      	Set<Id> caseIds = new Set<Id>();
      	Map<Id, Integer> commentCount = new Map<Id, Integer>();
      
      	List<CaseComment> comments = (Trigger.isInsert) ?
      	Trigger.new : Trigger.old;
      
      	for (CaseComment cc : comments) {
      		caseIds.add(cc.ParentId);
      		commentCount.put(cc.ParentId, 0);
      	}
      
      	for (Case c : [select OwnerId from Case where Id in :caseIds]) {
      		ownerIds.add(c.OwnerId);
      	}
      
      	for (CaseComment cc : [
      		select CreatedById,
      			ParentId
      		from CaseComment
      		where ParentId in :caseIds and
      		CreatedById in :ownerIds
      	]) {
      		commentCount.put(cc.ParentId,
      			commentCount.get(cc.ParentId) + 1
      		);
      	}
      
      	List<Case> casesToUpdate = new List<Case>();
      
      	for (Id id : commentCount.keySet()) {
      		casesToUpdate.add(new Case(
      			Id = id,
      			Owner_Comment_Count__c = commentCount.get(id)
      		));
      	}
      
      	update casesToUpdate;
      }