This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This class holds useful information about a trigger event that is taking | |
* place so that handler classes can make use of this data and don't have to | |
* pass any individual values. | |
*/ | |
public class TriggerContext { | |
public final String objectName; | |
public final Boolean isBefore; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Build { | |
//------------------------------------------------------------------------------ | |
//Account | |
public class AccountBuilder { | |
public AccountBuilder withName(String name) { | |
this.name = name; | |
return this; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Copyright 2011 Mavens Consulting, Inc. | |
Licensed under the Apache License, Version 2.0 (the "License"); | |
you may not use this file except in compliance with the License. | |
You may obtain a copy of the License at | |
http://www.apache.org/licenses/LICENSE-2.0 | |
Unless required by applicable law or agreed to in writing, software |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@isTest | |
public static void testObjectAOwnership() { | |
Account owningAccount = Build.anAccount() | |
.withRecordType(Build.AccountRecordType.Account) | |
.withName('testOwningAccount') | |
.build(); | |
insert owningAccount; | |
Account secondOwningAccount = Build.anAccount() | |
.withRecordType(Build.AccountRecordType.Account) | |
.withName('testOwningAccount2') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void manageSharingObjectA(List<sObject> objectList) { | |
//Obtain the security configuration map | |
Map<String, SecurityDictionary__c> securityDictionaryMap = SecurityDictionary__c.getAll(); | |
Set<Id> objectAIdsTargetedToReview = new Set<Id>(); | |
List<ObjectA__Share> objectAShareToInsert = new List<ObjectA__Share>(); | |
List<ObjectA__Share> objectAShareToDelete = new List<ObjectA__Share>(); | |
for (sObject objectAObject : objectList) { | |
ObjectA__c objectAToReview = (ObjectA__c) objectAObject; | |
objectAIdsTargetedToReview.add(objectAToReview.Id); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/////////////// | |
//Hierarchy tree sorter | |
/////////////// | |
//Initialising process to recalculate hierarchy for given accounts | |
//Any member of the account hierarchy can be identified in order to intiate a complete recalculation | |
public static void processAccountHierarchyMembership(Set<Id> targetedAccountsIds) { | |
//Given that the hierarchy code requires the top parent record, we first obtain the master parent records | |
Set<Id> topIds = getTopAccountIds(targetedAccountsIds); | |
List<Account> topAccounts = new List<Account>(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Method consumes two sets of Ids and returns a map of sets | |
//Primarily used for comparison of existing and new memberships to see what existing records have to be removed | |
public static Map<String, Set<Id>> compareSets(Set<Id> setOne, Set<Id> setTwo) { | |
Map<String, Set<Id>> comparisonMap = new Map<String, Set<Id>>{ | |
'In_First_Set' => new Set<Id>(), | |
'Present_In_Both' => new Set<Id>(), | |
'In_Second_Set' => new Set<Id>() | |
}; | |
for (String setOneString : setOne) { | |
if (setTwo.contains(setOneString)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Boolean GroupCalculationActive = false; | |
public static List<PublicGroupAccountWrapper> createPublicGroupSet(Set<Id> accountIdsTargeted) { | |
if (!GroupCalculationActive) { | |
GroupCalculationActive = true; | |
List<PublicGroupAccountWrapper> accountsToPopulate = new List<PublicGroupAccountWrapper>(); | |
Id organisationRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get(ConfigSupport.defaultOrganisationAccountRecordType).getRecordTypeId(); | |
//Given that the hierarchy code requires the top parent record, we first obtain the master parent records | |
Set<Id> topIds = getTopAccountIds(accountIdsTargeted); | |
List<Account> topAccounts = new List<Account>(); | |
for (Account acc: [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@isTest | |
private class TestUserUtil { | |
@isTest static void updateRelatedContactAndAccountRecordsTest() { | |
// Create a User, Contact and Account | |
Account newAccount = Build.anAccount() | |
.withRecordType(Build.AccountRecordType.Organisation) | |
.build(); | |
insert newAccount; | |
Contact contactForUser = Build.aContact() | |
.withName('Test1', 'Test2') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Account a = [SELECT Id, Name, | |
Owner.Manager.Manager.ManagerId | |
FROM Account | |
WHERE Id = '001p000000K12dV' LIMIT 1]; | |
System.debug('1: ' + a.OwnerId); | |
System.debug('2: ' + a.Owner.ManagerId); | |
System.debug('3: ' + a.Owner.Manager.Manager.Manager.Manager.FirstName); | |
System.debug('3: ' + a.Owner.Manager.LastName); |
NewerOlder