This file contains 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
/** | |
* Created by Nick Likane on 30/12/2016. | |
*/ | |
public without sharing class SecurityUtil { | |
// Default up down map | |
public static Boolean GroupCalculationActive = false; | |
////////// | |
//Managing of specific share records | |
////////// |
This file contains 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 Set<Id> getTopAccountIds(Set<Id> accountsTargeted) { | |
Set<Id> topAccountIds = new Set<Id>(); | |
Set<Id> recursivelyTargetedAccountIds = new Set<Id>(); | |
for (Account targetedAccount : [ | |
SELECT Id, | |
Name, | |
ChildrenUserGroupId__c, | |
ChildrenIncludedUserGroupId__c, | |
UserGroupId__c, | |
ParentUserGroupId__c, |
This file contains 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 Set<Id> getTopAccountIds(Set<Id> accountsTargeted) { | |
Set<Id> topAccountIds = new Set<Id>(); | |
Set<Id> recursivelyTargetedAccountIds = new Set<Id>(); | |
for (Account targetedAccount : [ | |
SELECT Id, | |
Name, | |
ChildrenUserGroupId__c, | |
ChildrenIncludedUserGroupId__c, | |
UserGroupId__c, | |
ParentUserGroupId__c, |
This file contains 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, | |
ParentID, | |
Parent.ParentId, | |
Parent.Parent.ParentId | |
FROM Account | |
WHERE Id = '0013600000NHSlW' LIMIT 1]; | |
System.debug('1: ' + a.ParentId); | |
System.debug('2: ' + a.Parent.ParentId); | |
System.debug('3: ' + a.Parent.Parent.ParentId); |
This file contains 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, | |
ParentID, | |
Parent.ParentId | |
FROM Account | |
WHERE Id = '001p000000K12dV' LIMIT 1]; |
This file contains 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, | |
Parent.Parent.Parent.ParentId | |
FROM Account | |
WHERE Id = '001p000000K12dV' LIMIT 1]; |
This file contains 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); |
This file contains 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); |
This file contains 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 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: [ |
OlderNewer