LIMIT_EXCEEDED, Maximum per user subscription limit reached (copy)

Problem : 

Chatter EntitySubscription Limits ?

In my project, we follow certain records via after update triggers, if some conditions match.

I am getting this error on follow code that creates an EntitySubscription via trigger

Description: Error:Apex trigger FollowXYZ caused an unexpected exception, contact your administrator: FollowXYZ: execution of AfterUpdate caused by: System.DmlException: Insert failed. First exception on row 0; first error: LIMIT_EXCEEDED, Maximum per user subscription limit reached.: []:

Solution :
  • Before Inserting the 'EntitySubscription' record, Get the count() subscription-id. 
  • If the subscription-id count() is greater then 500, then delete the older EntitySubscription records first, then proceed with inserting the new EntitySubscription records.

Code Snippet :

1) Count(userID)

SELECT count() FROM EntitySubscription  WHERE SubscriberId = '00530000005nnYnAAI'   AND ParentId IN ( SELECT Id FROM CASE WHERE CreatedDate = LAST_N_DAYS:365 AND Status      = 'Solved')

2) Delete(userID)


SELECT id, FROM EntitySubscription

WHERE SubscriberId = '00530000005nnYnAAI'
 
   AND ParentId IN (
 
 SELECT Id FROM CASE 
 
WHERE CreatedDate = LAST_N_DAYS:365 AND
 
 Status ='Solved' 

) Order by CreatedDate asc


Ex : Delete [SELECT id FROM EntitySubscription WHERE SubscriberId = '005a0000007pKz9AAE'  AND ParentId IN (SELECT Id FROM CASE WHERE CreatedDate = LAST_N_DAYS:365 AND Status ='Solved' ) Order by CreatedDate asc];

Comments

Popular posts from this blog

Adding a red asterisk to required fields using label in LWC

The Developer Console didn't set the DEVELOPER_LOG trace flag on your user. Having an active trace flag triggers debug logging. You have 1,978 MB of the maximum 1,000 MB of debug logs. Before you can edit trace flags, delete some debug logs.

Salesforce: Serial and Parallel Approval