You need to sign in to do that
Don't have an account?

Too Many DML Statements - Small Trigger
I am getting an error with Too Many DML Statements for a small trigger that I wrote. I know that it has to do with the insert being inside the loop, but I cannot figure out how to correctly write this. I am hoping someone can take a look since it is so small.
trigger ReferralChatterFollow on Referral__c (after insert) { for(Referral__c r: Trigger.New) { EntitySubscription follow = new EntitySubscription ( parentId = r.id, subscriberId = UserInfo.getUserId()); insert follow; } }
You have to insert all EntitiySubscriptions at once, so you avoid too many DML statements, issued by the INSERT statement inside your loop:
All Answers
You have to insert all EntitiySubscriptions at once, so you avoid too many DML statements, issued by the INSERT statement inside your loop:
This works perfectly, thank you so much! I would buy you a drink for all of your help with this project, but you live too far away!