Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * See what happens when you attempt to reparent a child record through a
- * Master-Detail field that is <em>not</em> configured to allow such
- * reparenting.
- *
- * This code was last run in a Winter '14 org.
- *
- * @version 0.1
- * @author Marty Chang (Slalom Consulting)
- */
- @isTest
- private class AliasUtilTest {
- /*
- * Attempt to reparent an alias. You will see that this is silently futile,
- * if child records are not allowed to be reparented.
- */
- public static testMethod void testThatAliasCannotBeReparented() {
- // Set up the test records
- Account acme = new Account(Name = 'Acme ApexTest Corporation');
- Account zenith = new Account(Name = 'Zenith ApexTest Corporation');
- insert new List<Account> { acme, zenith };
- Alias__c zen = new Alias__c(Name = 'Zen', Account__c = zenith.Id);
- insert zen;
- // Start the test
- Test.startTest();
- // Attempt to reparent the alias
- update new Alias__c(Id = zen.Id, Account__c = acme.Id);
- // Stop the test
- Test.stopTest();
- // Retrieve the alias as it now exists in the database.
- // What will the Account value be?
- List<Alias__c> matchedAliases = [
- SELECT Id, Account__c
- FROM Alias__c
- WHERE Id = :zen.Id
- ];
- System.assertEquals(zenith.Id, matchedAliases.get(0).Account__c,
- 'The Account value should not have changed, ' +
- 'if the Account field cannot be reparented');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement