diff --git a/src/main/default/classes/ChangeAccountOwner.cls b/src/main/default/classes/ChangeAccountOwner.cls index 0d78377c..68f6afdb 100644 --- a/src/main/default/classes/ChangeAccountOwner.cls +++ b/src/main/default/classes/ChangeAccountOwner.cls @@ -1,9 +1,9 @@ /** - * @Name : AccountContactRelationController - * @Description : This class transfer Account and related records Owners. - * @Author : Keerthana (Accenture) - * @StoryNo : ALR-134 - **/ +* @Name : AccountContactRelationController +* @Description : This class transfer Account and related records Owners. +* @Author : Keerthana (Accenture) +* @StoryNo : ALR-134 +**/ public with sharing class ChangeAccountOwner { @@ -28,93 +28,85 @@ public with sharing class ChangeAccountOwner { } @InvocableMethod(label='Transfer Account Ownership' description='Transfers ownership of Accounts and related records.') public static void transferAccountOwnership(List inputs) { - try { - FlowInputs input = inputs[0]; - - Id newOwnerId = input.newOwnerId; - List 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 accList = [SELECT Id, OwnerId FROM Account WHERE Id = :accountId]; - List blaRec; - List pubCompList; - List caseList; - List 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()); + try { + FlowInputs input = inputs[0]; + + Id newOwnerId = input.newOwnerId; + List 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 accList = [SELECT Id, OwnerId FROM Account WHERE Id = :accountId]; + List blaRec; + List pubCompList; + List caseList; + List 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; + } + Database.update(blaRec,FALSE) ; + } + + if(isPublicChecked == True){ + pubCompList = getRelatedPublicCompRecords(acc.Id,oldOwnerId); + for(PublicComplaint pubComp : pubCompList){ + pubComp.OwnerId = newOwnerId; + } + Database.update(pubCompList,FALSE) ; + } + + if(isCaseChecked == True){ + caseList = getRelatedCaseRecords(acc.Id,oldOwnerId); + for(Case caseRec : caseList){ + caseRec.OwnerId = newOwnerId; + } + Database.update(caseList,FALSE) ; + } + + if(isInspectionChecked == True){ + visitList = getRelatedVisitRecords(acc.Id,oldOwnerId); + for(Visit visit : visitList){ + visit.OwnerId = newOwnerId; + } + Database.update(visitList,FALSE) ; + } + } + Database.update(accList,FALSE) ; } -} + catch (Exception err) { + System.debug('Exception occurred: ' + err.getMessage()); + } + } + public static List 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 getRelatedPublicCompRecords(Id accountId, Id oldOwnerId){ + return [Select Id, OwnerId from PublicComplaint where AccountId =:accountId AND OwnerId=: oldOwnerId AND Status =: 'Needs Review']; + } + + public static List getRelatedCaseRecords(Id accountId, Id oldOwnerId){ + return [Select Id, OwnerId from Case where AccountId =:accountId AND OwnerId =: oldOwnerId AND Status != 'Closed']; + } + public static List getRelatedVisitRecords(Id accountId, Id oldOwnerId){ + return [Select Id, OwnerId from Visit where AccountId =:accountId AND OwnerId=: oldOwnerId AND Status != 'Completed']; + } - - public static List 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 getRelatedPublicCompRecords(Id accountId, Id oldOwnerId){ - return [Select Id, OwnerId from PublicComplaint where AccountId =:accountId AND OwnerId=: oldOwnerId AND Status =: 'Needs Review']; - } - - public static List getRelatedCaseRecords(Id accountId, Id oldOwnerId){ - return [Select Id, OwnerId from Case where AccountId =:accountId AND OwnerId =: oldOwnerId AND Status != 'Closed']; - } - - public static List getRelatedVisitRecords(Id accountId, Id oldOwnerId){ - return [Select Id, OwnerId from Visit where AccountId =:accountId AND OwnerId=: oldOwnerId AND Status != 'Completed']; - } - } \ No newline at end of file