Skip to content

Commit

Permalink
Merge pull request #951 from bcgov/feature-ALR-134
Browse files Browse the repository at this point in the history
ALR-134
  • Loading branch information
GandlojuVishwantha authored Jul 12, 2024
2 parents 93d3aeb + 95972b7 commit 2f8ba58
Show file tree
Hide file tree
Showing 13 changed files with 654 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<ListView xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>Requests_Inquiries_Case</fullName>
<columns>CASES.CASE_NUMBER</columns>
<columns>NAME</columns>
<columns>CASES.SUBJECT</columns>
<columns>CASES.STATUS</columns>
<columns>CASES.PRIORITY</columns>
<columns>CASES.CREATED_DATE</columns>
<columns>CORE.USERS.ALIAS</columns>
<filterScope>Everything</filterScope>
<filters>
<field>CASES.RECORDTYPE</field>
<operation>equals</operation>
<value>Case.Requests_Inquiries</value>
</filters>
<label>Requests &amp; Inquiries Case</label>
</ListView>
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,9 @@
<excludedStandardButtons>Import</excludedStandardButtons>
<excludedStandardButtons>MassCreateCallList</excludedStandardButtons>
<excludedStandardButtons>PrintableListView</excludedStandardButtons>
<excludedStandardButtons>SendBulkMessageAction</excludedStandardButtons>
<excludedStandardButtons>MassAddToActionableList</excludedStandardButtons>
<excludedStandardButtons>NavigateToAccountDiscoveryDashboard</excludedStandardButtons>
<listViewButtons>ChangeOwner</listViewButtons>
<lookupDialogsAdditionalFields>ACCOUNT.NAME</lookupDialogsAdditionalFields>
<lookupDialogsAdditionalFields>CORE.USERS.ALIAS</lookupDialogsAdditionalFields>
<lookupDialogsAdditionalFields>ACCOUNT.TYPE</lookupDialogsAdditionalFields>
Expand Down
120 changes: 120 additions & 0 deletions src/main/default/classes/ChangeAccountOwner.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/**
* @Name : AccountContactRelationController
* @Description : This class transfer Account and related records Owners.
* @Author : Keerthana (Accenture)
* @StoryNo : ALR-134
**/

public with sharing class ChangeAccountOwner {

public class FlowInputs {
@InvocableVariable
public Id newOwnerId;

@InvocableVariable
public List<Id> accountId;

@InvocableVariable
public Boolean isBlaChecked;

@InvocableVariable
public Boolean isPublicChecked;

@InvocableVariable
public Boolean isCaseChecked;

@InvocableVariable
public Boolean isInspectionChecked;
}
@InvocableMethod(label='Transfer Account Ownership' description='Transfers ownership of Accounts and related records.')
public static void transferAccountOwnership(List<FlowInputs> inputs) {
try {
FlowInputs input = inputs[0];

Id newOwnerId = input.newOwnerId;
List<Id> accountId = input.accountId;
Boolean isBlaChecked = input.isBlaChecked;
Boolean isPublicChecked = input.isPublicChecked;
Boolean isCaseChecked = input.isCaseChecked;
Boolean isInspectionChecked = input.isInspectionChecked;


if (newOwnerId == null || accountId.isEmpty()) {
return;
}


List<Account> accList = [SELECT Id, OwnerId FROM Account WHERE Id = :accountId];
List<BusinessLicenseApplication> blaRec;
List<PublicComplaint> pubCompList;
List<Case> caseList;
List<Visit> visitList;

for(Account acc : accList){
Id oldOwnerId = acc.OwnerId;

{
acc.OwnerId = newOwnerId;
}

if(isBlaChecked == True){
blaRec = getRelatedBlaRecords(acc.Id,oldOwnerId);
for(BusinessLicenseApplication bla : blaRec){
bla.OwnerId = newOwnerId;
}
}

if(isPublicChecked == True){
pubCompList = getRelatedPublicCompRecords(acc.Id,oldOwnerId);
for(PublicComplaint pubComp : pubCompList){
pubComp.OwnerId = newOwnerId;
}

}

if(isCaseChecked == True){
caseList = getRelatedCaseRecords(acc.Id,oldOwnerId);
for(Case caseRec : caseList){
caseRec.OwnerId = newOwnerId;
}
}

if(isInspectionChecked == True){
visitList = getRelatedVisitRecords(acc.Id,oldOwnerId);
for(Visit visit : visitList){
visit.OwnerId = newOwnerId;
}

}
}
update blaRec;
update pubCompList;
update caseList;
update visitList;
update accList;
}
catch (Exception e) {
System.debug('Exception occurred: ' + e.getMessage());

}
}



public static List<BusinessLicenseApplication> getRelatedBlaRecords(Id accountId, Id oldOwnerId){
return [Select Id, OwnerId from BusinessLicenseApplication where AccountId =:accountId AND OwnerId=: oldOwnerId AND RecordType.Name='New License' AND Status !='Closed'];
}

public static List<PublicComplaint> getRelatedPublicCompRecords(Id accountId, Id oldOwnerId){
return [Select Id, OwnerId from PublicComplaint where AccountId =:accountId AND OwnerId=: oldOwnerId AND Status =: 'Needs Review'];
}

public static List<Case> getRelatedCaseRecords(Id accountId, Id oldOwnerId){
return [Select Id, OwnerId from Case where AccountId =:accountId AND OwnerId =: oldOwnerId AND Status != 'Closed'];
}

public static List<Visit> getRelatedVisitRecords(Id accountId, Id oldOwnerId){
return [Select Id, OwnerId from Visit where AccountId =:accountId AND OwnerId=: oldOwnerId AND Status != 'Completed'];
}

}
5 changes: 5 additions & 0 deletions src/main/default/classes/ChangeAccountOwner.cls-meta.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>61.0</apiVersion>
<status>Active</status>
</ApexClass>
80 changes: 80 additions & 0 deletions src/main/default/classes/ChangeAccountOwnerTest.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* @Name : AccountContactRelationController
* @Description : This Test class transfer Account and related records Owners.
* @Author : Keerthana (Accenture)
* @StoryNo : ALR-134
**/

@isTest
private class ChangeAccountOwnerTest {

@isTest
static void testTransferAccountOwnership() {


Id adminId =[Select Id From Profile where Name='System Administrator'].Id;

User oldUser = new User(
FirstName = 'oldUser',
LastName = 'User',
Username = '[email protected]',
Email = '[email protected]',
Alias = 'ouser',
ProfileId = adminId,
CommunityNickname = 'old987user',
TimeZoneSidKey = 'GMT',
LocaleSidKey = 'en_US',
EmailEncodingKey = 'UTF-8',
LanguageLocaleKey = 'en_US'
);
insert oldUser;


User newUser = new User(
FirstName = 'Test',
LastName = 'User1',
Username = '[email protected]',
Email = '[email protected]',
Alias = 'tuser',
ProfileId = adminId,
CommunityNickname = 'test123user',
TimeZoneSidKey = 'GMT',
LocaleSidKey = 'en_US',
EmailEncodingKey = 'UTF-8',
LanguageLocaleKey = 'en_US'
);
insert newUser;

Schema.Location loc = new Schema.Location();
loc.Name = 'U.S. 101N';
loc.Longitude = 28.635308;
loc.Latitude = 28.635308;
insert loc;

RegulatoryAuthorizationType regAuth = TestDataFactory.createRegAuth('Mental Helath', 'License', 'MH', 1, 2, 3, 4, true);
Account acc = TestDataFactory.createResidence('Residence', 'Test Residence', regAuth.Id, true);


Case caseRec = new Case(AccountId=acc.Id, Status='Under Inspection',OwnerId=oldUser.Id);
insert caseRec;

BusinessLicenseApplication bla = TestDataFactory.createRenewalBla(acc.LicenseType__c, acc.Id, true);

ChangeAccountOwner.FlowInputs flowInputs = new ChangeAccountOwner.FlowInputs();
flowInputs.newOwnerId = newUser.Id;
flowInputs.accountId = new List<Id>{ acc.Id };
flowInputs.isBlaChecked = true;
flowInputs.isPublicChecked = true;
flowInputs.isCaseChecked = true;
flowInputs.isInspectionChecked = true;

List<ChangeAccountOwner.FlowInputs> inputs = new List<ChangeAccountOwner.FlowInputs>{ flowInputs };

Test.startTest();
ChangeAccountOwner.transferAccountOwnership(inputs);
Test.stopTest();

List<Account> updatedAccount = [SELECT Id FROM Account];
Assert.isNotNull(updatedAccount.size());
}
}
5 changes: 5 additions & 0 deletions src/main/default/classes/ChangeAccountOwnerTest.cls-meta.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>61.0</apiVersion>
<status>Active</status>
</ApexClass>
Loading

0 comments on commit 2f8ba58

Please sign in to comment.