generated from navikt/crm-shared-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #578 from navikt/update_subject_batch
update subjects on old active STO/BTO cases batchjob
- Loading branch information
Showing
4 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
force-app/main/default/classes/UpdateCaseSubjectsBatch.cls
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
public with sharing class UpdateCaseSubjectsBatch implements Database.Batchable<sObject> { | ||
public Database.QueryLocator start(Database.BatchableContext BC) { | ||
return Database.getQueryLocator( | ||
'SELECT STO_ExternalName__c, CRM_Case__c, CRM_Case__r.Subject FROM Thread__c WHERE CRM_Is_Closed__c = FALSE AND CRM_Thread_Type__c IN (\'STO\', \'BTO\') AND CRM_Case__c != NULL AND STO_ExternalName__c != NULL' | ||
); | ||
} | ||
public void execute(Database.BatchableContext BC, List<Thread__c> scope) { | ||
List<Case> casesToUpdate = new List<Case>(); | ||
|
||
for (Thread__c threadRecord : scope) { | ||
Case caseToUpdate = new Case(Id = threadRecord.CRM_Case__c, Subject = threadRecord.STO_ExternalName__c); | ||
casesToUpdate.add(caseToUpdate); | ||
} | ||
|
||
if (!casesToUpdate.isEmpty()) { | ||
Database.update(casesToUpdate); | ||
} | ||
} | ||
public void finish(Database.BatchableContext BC) { | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
force-app/main/default/classes/UpdateCaseSubjectsBatch.cls-meta.xml
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
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>59.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
44 changes: 44 additions & 0 deletions
44
force-app/main/default/classes/UpdateCaseSubjectsBatchTest.cls
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
@isTest | ||
private class UpdateCaseSubjectsBatchTest { | ||
@isTest | ||
static void testBatchExecution() { | ||
// Create test data - Thread records with associated Cases | ||
List<Thread__c> threads = new List<Thread__c>(); | ||
List<Case> cases = new List<Case>(); | ||
|
||
Case testCase = new Case(); | ||
Case testCase2 = new Case(); | ||
cases.add(testCase); | ||
cases.add(testCase2); | ||
insert cases; | ||
|
||
Thread__c testThread = new Thread__c( | ||
CRM_Case__c = testCase.Id, | ||
CRM_Thread_Type__c = 'STO', | ||
CRM_Type__c = 'STO' | ||
); | ||
Thread__c testThread2 = new Thread__c( | ||
CRM_Case__c = testCase2.Id, | ||
CRM_Thread_Type__c = 'STO', | ||
CRM_Type__c = 'STO' | ||
); | ||
threads.add(testThread); | ||
threads.add(testThread2); | ||
insert threads; | ||
|
||
Test.startTest(); | ||
System.debug( | ||
[ | ||
SELECT STO_ExternalName__c, CRM_Case__c, CRM_Case__r.Subject, CRM_Is_Closed__c, CRM_Thread_Type__c | ||
FROM Thread__c | ||
] | ||
); | ||
UpdateCaseSubjectsBatch batch = new UpdateCaseSubjectsBatch(); | ||
Database.executeBatch(batch); | ||
Test.stopTest(); | ||
|
||
List<Case> updatedCases = [SELECT Id, Subject FROM Case WHERE Id IN :cases]; | ||
Assert.areNotEqual(null, updatedCases[0].Subject); | ||
Assert.areNotEqual(null, updatedCases[1].Subject); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
force-app/main/default/classes/UpdateCaseSubjectsBatchTest.cls-meta.xml
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
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>59.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |