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 #190 from navikt/TOLK-2508
TOLK-2508 - varsling til saksbehandler når det blir sendt inn nytt krav av en ikke-lesehjelp, og når bruker ikke har noen vedtak
- Loading branch information
Showing
5 changed files
with
120 additions
and
2 deletions.
There are no files selected for viewing
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
92 changes: 92 additions & 0 deletions
92
force-app/main/default/classes/HOT_ClaimNotificationService.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,92 @@ | ||
public without sharing class HOT_ClaimNotificationService { | ||
@Future | ||
public static void NotifyNAVNoEntitlementOnUser(List<Id> claimIds) { | ||
List<HOT_Claim__c> claims = [ | ||
SELECT Id, Name, Account__c | ||
FROM HOT_Claim__c | ||
WHERE Id IN :claimIds | ||
]; | ||
Set<Id> accountIds = new Set<Id>(); | ||
Map<Id, HOT_Claim__c> claimMap = new Map<Id, HOT_Claim__c>(); | ||
for(HOT_Claim__c claim : claims){ | ||
accountIds.add(claim.Account__c); | ||
claimMap.put(claim.Account__c, claim); | ||
} | ||
List<HOT_Entitlement__c> entitlements = [ | ||
SELECT Id, Account__c | ||
FROM HOT_Entitlement__c | ||
WHERE Account__c IN :accountIds | ||
]; | ||
|
||
Set<Id> entitledAccountIds = new Set<Id>(); | ||
for(HOT_Entitlement__c entitlement : entitlements){ | ||
entitledAccountIds.add(entitlement.Account__c); | ||
} | ||
List<User> navUsers =[SELECT Id FROM User WHERE Id in (SELECT userorgroupid from groupmember where group.name = 'HOT LOS Saksbehandler')]; | ||
|
||
for(Id accountId : accountIds){ | ||
if (!entitledAccountIds.contains(accountId)) { | ||
HOT_Claim__c claim = claimMap.get(accountId); | ||
if (claim != null) { | ||
for(User user : navUsers){ | ||
Set<String> recipients = new Set<String>(); | ||
recipients.add(user.Id); | ||
Messaging.CustomNotification notification = new Messaging.CustomNotification(); | ||
notification.setTitle('Lesehjelp har sendt inn krav på en bruker som ikke har noen vedtak'); | ||
notification.setBody('Legg på vedtak på brukeren'); | ||
notification.setNotificationTypeId(getCustomNotificationType('HOT_ClaimNotification').Id); | ||
notification.setTargetId(claim.Id); | ||
sendNotification(notification, recipients, (SObject) claim); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Future | ||
public static void NotifyNAVNotRegisteredReader(List<Id> claimIds) { | ||
List<HOT_Claim__c> claims = [ | ||
SELECT Id, Name | ||
FROM HOT_Claim__c | ||
WHERE Id IN :claimIds | ||
]; | ||
List<User> navUsers =[SELECT Id FROM User WHERE Id in (SELECT userorgroupid from groupmember where group.name = 'HOT LOS Saksbehandler')]; | ||
|
||
for(HOT_Claim__c claim : claims){ | ||
for(User user : navUsers){ | ||
Set<String> recipients = new Set<String>(); | ||
recipients.add(user.Id); | ||
Messaging.CustomNotification notification = new Messaging.CustomNotification(); | ||
notification.setTitle('Lesehjelp uten ressursnummer'); | ||
notification.setBody('Lesehjelp uten ressursnummer har sendt inn et nytt krav'); | ||
notification.setNotificationTypeId(getCustomNotificationType('HOT_ClaimNotification').Id); | ||
notification.setTargetId(claim.Id); | ||
sendNotification(notification, recipients, (SObject) claim); | ||
} | ||
} | ||
} | ||
public static CustomNotificationType getCustomNotificationType(String devName) { | ||
CustomNotificationType notificationType = [ | ||
SELECT Id, DeveloperName | ||
FROM CustomNotificationType | ||
WHERE DeveloperName = :devName | ||
]; | ||
return notificationType; | ||
} | ||
public static void sendNotification( | ||
Messaging.CustomNotification notification, | ||
Set<String> recipients, | ||
SObject record | ||
) { | ||
LoggerUtility logger = new LoggerUtility(); | ||
|
||
if (recipients != null && recipients.size() > 0) { | ||
try { | ||
notification.send(recipients); | ||
} catch (Exception e) { | ||
logger.exception(e, record, CRM_ApplicationDomain.Domain.HOT); | ||
logger.publishSynch(); | ||
} | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
force-app/main/default/classes/HOT_ClaimNotificationService.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>56.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
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
8 changes: 8 additions & 0 deletions
8
force-app/main/default/notificationtypes/HOT_ClaimNotification.notiftype-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,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<CustomNotificationType xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<customNotifTypeName>HOT_ClaimNotification</customNotifTypeName> | ||
<desktop>true</desktop> | ||
<masterLabel>HOT_ClaimNotification</masterLabel> | ||
<mobile>false</mobile> | ||
<slack>false</slack> | ||
</CustomNotificationType> |