-
-
Save arun12209/2b878206993ac63c9d823bef8cdb259d to your computer and use it in GitHub Desktop.
AccountController.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
public with sharing class AccountController { | |
@AuraEnabled(cacheable=true) | |
public static List<Account> getSubscribedAccounts() { | |
List<Account> subscribedAccounts = new List<Account>(); | |
Set<Id> accountIds = new Set<Id>(); | |
List<EntitySubscription> subscriptions = [ | |
SELECT ParentId | |
FROM EntitySubscription | |
WHERE SubscriberId = :UserInfo.getUserId() | |
]; | |
Set<Id> accountRecordTypeIds = new Set<Id>(); | |
for (EntitySubscription subscription : subscriptions) { | |
if (subscription.ParentId.getSObjectType() == Account.sObjectType) { | |
accountIds.add(subscription.ParentId); | |
accountRecordTypeIds.add(subscription.ParentId); | |
} | |
} | |
if (!accountRecordTypeIds.isEmpty()) { | |
subscribedAccounts = [ | |
SELECT Id, Name | |
FROM Account | |
WHERE Id IN :accountRecordTypeIds | |
]; | |
} | |
return subscribedAccounts; | |
} | |
@AuraEnabled | |
public static Boolean removeAccountSubscription(Id accountId) { | |
try { | |
List<EntitySubscription> subscriptions = [ | |
SELECT Id | |
FROM EntitySubscription | |
WHERE SubscriberId = :UserInfo.getUserId() | |
AND ParentId = :accountId | |
AND Parent.Type = 'Account' | |
]; | |
if (!subscriptions.isEmpty()) { | |
delete subscriptions; | |
return true; | |
} | |
} catch (Exception ex) { | |
System.debug('Error removing account subscription: ' + ex.getMessage()); | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment