Guest User

Untitled

a guest
Jan 25th, 2018
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.85 KB | None | 0 0
  1. boolean bByPass = false;
  2. if (UPSUtility.ByPassCurrentUser() != null && UPSUtility.ByPassCurrentUser().Bypass_Account_Object_Validation_Rules__c)
  3. bByPass = true;
  4.  
  5. if (!bByPass){
  6. if(!Constants.bTriggerRecursionCheck)
  7. {
  8. if (Trigger.IsBefore && (Trigger.IsInsert || Trigger.IsUpdate)){
  9. Constants.bTriggerRecursionCheck = true;
  10. AccountTriggerHandler.validateProspectAccountForSite(Trigger.new);
  11. AccountTriggerHandler.UpdateDistrictName(trigger.new);
  12. //AccountTriggerHandler.HIEChangeToNoneInsert(Trigger.new);
  13. }
  14.  
  15. if (Trigger.IsBefore && Trigger.IsUpdate){
  16. AccountTriggerHandler.OwnerChangeUpdate(Trigger.oldMap,Trigger.newMap,Trigger.new);
  17. //AccountTriggerHandler.HIEChangeToNoneUpdate(Trigger.oldMap,Trigger.newMap,Trigger.new);
  18. AccountTriggerHandler.assignedAccountRVARecordType(Trigger.old,Trigger.new,true);
  19. }
  20.  
  21. if (Trigger.IsBefore && Trigger.IsInsert){
  22. AccountTriggerHandler.assignedAccountRVARecordType(null,Trigger.new,false);
  23. }
  24. }
  25. if(Trigger.isAfter && Trigger.isUpdate){
  26. AccountTriggerHandler.assignedLeadContactRVARecordType(Trigger.old,Trigger.new);
  27. }
  28. }
  29.  
  30. if(Trigger.isAfter && (Trigger.isInsert || Trigger.isUpdate || Trigger.isUndelete)){
  31. Map<Id,Account> mapAccToProcess = new Map<Id,Account>();
  32. Set<Id>AccountIds = new set<ID>();
  33. for(Account acc : Trigger.New){
  34. if(acc.RecordType.DeveloperName != 'Site'){
  35. if(Trigger.isInsert || Trigger.isUndelete){
  36. mapAccToProcess.put(acc.Id, acc);
  37. }
  38. else if(acc.OwnerId != Trigger.oldMap.get(acc.Id).OwnerId || acc.Name != Trigger.oldMap.get(acc.Id).Name || acc.Account_Number_Interface_Key__c != Trigger.oldMap.get(acc.Id).Account_Number_Interface_Key__c){
  39. mapAccToProcess.put(acc.Id, acc);
  40. AccountIds.add(acc.Id);
  41. system.debug('Account Ids' +AccountIds);
  42.  
  43. }
  44. }
  45. }
  46. if(AccountIds.size() >0){
  47. AccountTriggerHandler.updatePTOwner(AccountIds);
  48. }
  49. if(mapAccToProcess.size() > 0){
  50. AccountTriggerHandler.createUpdateSAD(mapAccToProcess);
  51. }
  52. }
  53.  
  54. if(Trigger.isBefore && Trigger.isDelete){
  55. AccountTriggerHandler.deleteSAD(Trigger.oldMap);
  56. }
  57.  
  58. for (integer iIterationCount =0;iIterationCount<10;iIterationCount++)
  59. {
  60. string AccName = String.fromCharArray(new Integer[]{65 + iIterationCount}) + ':';
  61. SubLevelAccount = UtilityForTestClass.createAccountBulk( 100, parnetAccount,AccName);
  62. insert SubLevelAccount;
  63. system.debug('check ---'+SubLevelAccount.size());
  64. parnetAccount = SubLevelAccount[50];
  65. AllAccounts.addAll(SubLevelAccount);
  66. }
  67.  
  68. return AllAccounts;
  69. }
  70.  
  71. static TestMethod void checkAccountHeirArchydesearilisation()
  72. {
  73. UPSTestUtility testUtilObj = new UPSTestUtility();
  74.  
  75. Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator'];
  76. try
  77. {
  78. UPSD_Bypass_Validation_Rules_Triggers__c custSettingBypassValidation = testUtilObj.buildBypassValidationRulesCustomSettingRecord(p.id,'AccountHeirarchy_Build_Test');
  79. if(custSettingBypassValidation!=null)
  80. {
  81. insert custSettingBypassValidation;
  82. }
  83. }
  84. catch(Exception ex)
  85. {
  86. System.debug('Exception caught - '+ex.getMessage());
  87. }
  88. User stdUser = new User(Alias = 'standt', Email='standardUPSuser@UPSTEST.com',
  89. EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
  90. TimeZoneSidKey='America/Los_Angeles',LocaleSidKey='en_US', ProfileId = p.Id,UserName='standardUPSuser@UPSTEST.com');
  91. insert stdUser;
  92. list<Account> AllAccounts = insertAccountHeirarchy();
  93. integer iRanDomAccountNumber = integer.Valueof(Math.Floor(Math.Random()*10));
  94. AccountTeamMember atm = new AccountTeamMember(userId = stdUser.id, AccountId = AllAccounts[iRanDomAccountNumber].id);
  95. insert atm;
  96. Account acct= new Account(name='test', Top_Level_Parent_Account_Number__c='ABCT123456609');
  97. insert acct;
  98. Account acct1= new Account(name='test', Top_Level_Parent_Account_Number__c='ABCT123456609', ParentId= acct.id);
  99. insert acct1;
  100. Account acct2= new Account(name='test', Top_Level_Parent_Account_Number__c='ABCT123456609', ParentId= acct1.id);
  101. insert acct2;
  102.  
  103. integer iCount = [select count() from Account];
  104. system.debug('# Account Records--' + iCount);
  105. //AccountHeirarchy_Built AccHeir = new AccountHeirarchy_Built();
  106. Test.startTest();
  107. string jSonReturnVal = AccountHeirarchy_Built.GetAlltheAccountsOfUser(stdUser.id);
  108. //AccountHeirarchyPageClass.GetAlltheAccountsOfUser(acct1.Id);
  109. Test.stopTest();
  110. list<AccountHeirarchy_Built.AccountBox> lstAccountBox = (list<AccountHeirarchy_Built.AccountBox>)JSON.deserialize(jSonReturnVal,list<AccountHeirarchy_Built.AccountBox>.class);
  111. integer iCountLstSize = lstAccountBox.size() - 1;
  112. //system.assert(lstAccountBox[0].sAccountname == 'EGN', 'Apex Account is not EGN');
  113. checkAssertion(lstAccountBox[0].lstchild );
  114. //system.assert(AllAccounts.size() == totalAccountCount, 'Account Insert do match with number of Account parsed');
  115.  
  116. }
  117.  
  118. static void checkAssertion(list<AccountHeirarchy_Built.AccountBox> lstAccountBox )
  119. {
  120. integer countThisIteration = 0;
  121.  
  122. for (AccountHeirarchy_Built.AccountBox acc : lstAccountBox)
  123. {
  124. //system.assert(acc.sAccountName.contains(String.fromCharArray(new Integer[]{65 + iter}) + ':'),
  125. // '----sAccountName----' + acc.sAccountName + '---string ----'
  126. //+ String.fromCharArray(new Integer[]{65 + iter}) + ':' + '---------pop--' + countThisIteration + '---Iter --- ' + iter);
  127. totalAccountCount++;
  128. if (!acc.lstchild.IsEmpty())
  129. {
  130. iter++;
  131. checkAssertion(acc.lstchild);
  132. iter--;
  133. }
  134. countThisIteration++;
  135. }
  136. }
Add Comment
Please, Sign In to add comment