Advertisement
martyychang

ActivityHistoryTest

Jan 28th, 2014
930
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.79 KB | None | 0 0
  1. /*
  2.  * Created in response to a Salesforce Stack Exchange Question:
  3.  * Unit Tests: create completed tasks for ActivityHistory?
  4.  * http://salesforce.stackexchange.com/questions/25323/unit-tests-create-completed-tasks-for-activityhistory
  5.  *
  6.  * @version 1.0
  7.  * @author  Marty Chang (Slalom Consulting)
  8.  */
  9. @isTest(SeeAllData = true)
  10. private class ActivityHistoryTest {
  11.    
  12.     /*
  13.      * Verify that a completed activity inserted for an Account causes
  14.      * an ActivityHistory record to be generated.
  15.      *
  16.      * It is interesting to note that without the <code>SeeAllData</code>
  17.      * modifier set to <code>true</code> for the <code>isTest</code> annotation,
  18.      * the final validation assertion will fail.
  19.      */
  20.     private static testMethod void testThatActivityHistoryObjectIsPopulatedOnTaskCompletion() {
  21.        
  22.         // Set up the test data
  23.        
  24.         Account acme = new Account(Name = 'Acme Corporation');
  25.         insert acme;
  26.        
  27.         // Start the test
  28.        
  29.         Test.startTest();
  30.        
  31.         // Complete an activity
  32.        
  33.         Task readAccount = new Task(
  34.             OwnerId = UserInfo.getUserId(),
  35.             WhatId = acme.Id,
  36.             Subject = 'Read Account: Acme Corporation',
  37.             Description = 'You better read this fast! Hot account here!',
  38.             Status = 'Completed'
  39.         );
  40.         insert readAccount;
  41.        
  42.         // Stop the test
  43.        
  44.         Test.stopTest();
  45.        
  46.         // Validate the results
  47.        
  48.         acme = [
  49.             SELECT Id, Name, (SELECT Id, CreatedDate FROM ActivityHistories)
  50.             FROM Account
  51.             WHERE Id = :acme.Id
  52.         ];
  53.        
  54.         System.assertEquals(1, acme.ActivityHistories.size());
  55.     }
  56. }   // private class ActivityHistoryTest
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement