Advertisement
martyychang

AliasUtilTest.testThatAliasCannotBeReparented()

Feb 21st, 2014
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.57 KB | None | 0 0
  1. /*
  2.  * See what happens when you attempt to reparent a child record through a
  3.  * Master-Detail field that is <em>not</em> configured to allow such
  4.  * reparenting.
  5.  *
  6.  * This code was last run in a Winter '14 org.
  7.  *
  8.  * @version 0.1
  9.  * @author  Marty Chang (Slalom Consulting)
  10.  */
  11. @isTest
  12. private class AliasUtilTest {
  13.    
  14.     /*
  15.      * Attempt to reparent an alias. You will see that this is silently futile,
  16.      * if child records are not allowed to be reparented.
  17.      */
  18.     public static testMethod void testThatAliasCannotBeReparented() {
  19.  
  20.         // Set up the test records
  21.  
  22.         Account acme = new Account(Name = 'Acme ApexTest Corporation');
  23.         Account zenith = new Account(Name = 'Zenith ApexTest Corporation');
  24.  
  25.         insert new List<Account> { acme, zenith };
  26.  
  27.         Alias__c zen = new Alias__c(Name = 'Zen', Account__c = zenith.Id);
  28.  
  29.         insert zen;
  30.  
  31.         // Start the test
  32.  
  33.         Test.startTest();
  34.  
  35.         // Attempt to reparent the alias
  36.  
  37.         update new Alias__c(Id = zen.Id, Account__c = acme.Id);
  38.  
  39.         // Stop the test
  40.  
  41.         Test.stopTest();
  42.  
  43.         // Retrieve the alias as it now exists in the database.
  44.         // What will the Account value be?
  45.  
  46.         List<Alias__c> matchedAliases = [
  47.             SELECT Id, Account__c
  48.             FROM Alias__c
  49.             WHERE Id = :zen.Id
  50.         ];
  51.  
  52.         System.assertEquals(zenith.Id, matchedAliases.get(0).Account__c,
  53.             'The Account value should not have changed, ' +
  54.                 'if the Account field cannot be reparented');
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement