Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Created in response to a Salesforce Stack Exchange Question:
- * Unit Tests: create completed tasks for ActivityHistory?
- * http://salesforce.stackexchange.com/questions/25323/unit-tests-create-completed-tasks-for-activityhistory
- *
- * @version 1.0
- * @author Marty Chang (Slalom Consulting)
- */
- @isTest(SeeAllData = true)
- private class ActivityHistoryTest {
- /*
- * Verify that a completed activity inserted for an Account causes
- * an ActivityHistory record to be generated.
- *
- * It is interesting to note that without the <code>SeeAllData</code>
- * modifier set to <code>true</code> for the <code>isTest</code> annotation,
- * the final validation assertion will fail.
- */
- private static testMethod void testThatActivityHistoryObjectIsPopulatedOnTaskCompletion() {
- // Set up the test data
- Account acme = new Account(Name = 'Acme Corporation');
- insert acme;
- // Start the test
- Test.startTest();
- // Complete an activity
- Task readAccount = new Task(
- OwnerId = UserInfo.getUserId(),
- WhatId = acme.Id,
- Subject = 'Read Account: Acme Corporation',
- Description = 'You better read this fast! Hot account here!',
- Status = 'Completed'
- );
- insert readAccount;
- // Stop the test
- Test.stopTest();
- // Validate the results
- acme = [
- SELECT Id, Name, (SELECT Id, CreatedDate FROM ActivityHistories)
- FROM Account
- WHERE Id = :acme.Id
- ];
- System.assertEquals(1, acme.ActivityHistories.size());
- }
- } // private class ActivityHistoryTest
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement