You need to sign in to do that
Don't have an account?
Skeeter
Too Many SOQL Queries
Not sure what I'm missing to get the error. Any help is greatly appreciated.
Test Class
Trigger
Test Class
@isTest(SeeAllData=true) private class ChatterFeedItemTest { static testMethod void TestChatterFeedInsert() { User cl = [SELECT Id From User WHERE ID = :UserInfo.getUserId()]; Escalated_Ticket__c inc = new Escalated_Ticket__c(); inc.Client__c = cl.id; inc.Summary__c = 'Test Subject'; inc.Description__c = 'Test Description'; inc.Client_Updated__c = False; insert inc; //Start Test Test.startTest(); // Create Chatter Post on test incident FeedItem testFeed1 = new FeedItem(); testFeed1.ParentId = inc.Id; testFeed1.Body = 'Test Feed 1 Post'; testFeed1.Type = 'TextPost'; insert testFeed1; // Create Chatter Comment on test incident FeedComment testFeed1Comment = new FeedComment(); testFeed1Comment.CommentBody = 'Test Feed 1 Comment'; testFeed1Comment.FeedItemId = testFeed1.Id; testFeed1Comment.CommentType='TextComment'; insert testFeed1Comment; // Create Chatter Post on test incident FeedItem testFeed2 = new FeedItem(); testFeed2.Body ='Test Feed 2 Post'; testFeed2.ParentId = inc.Id; testFeed2.Type = 'TextPost'; insert testFeed2; // Create Chatter Comment on test incident FeedComment testFeed2Comment = new FeedComment(); testFeed2Comment.CommentBody ='#answer Test Feed 2 Comment'; testFeed2Comment.FeedItemId = testFeed2.Id; testFeed2Comment.CommentType='TextComment'; insert testFeed2Comment; //Update Test Incident inc.Client_Updated__c = True; update inc; //Stop Test Test.stopTest(); } }
Trigger
trigger ChatterFeedItemTriggerAI on FeedItem (after insert) { //Collect all ParentIds into a set Set<Id>incIds = new Set<Id>(); //List of all Escalated Tickets to be updated with the flag List<Escalated_Ticket__c> toUpdate = new List<Escalated_Ticket__c>(); //Collect all ParentIds for(FeedItem i : trigger.New){ if(i.ParentId.getSobjectType() == Escalated_Ticket__c.SobjectType && i.Type == 'TextPost'){ incIds.add(i.ParentId); } } //Collect all escalated ticket records with the above list of parentIds and return only those records Map<Id,Escalated_Ticket__c> mapofInc = new Map<Id,Escalated_Ticket__c>([select Id,Client__c,Client_Updated__c from Escalated_Ticket__c where id in:incIds]); Boolean updateValues = false; for(FeedItem i : trigger.new){ if(mapofInc.ContainsKey(i.ParentId)){ if(mapofInc.get(i.ParentId).Client__c == i.CreatedById){ mapofInc.get(i.ParentId).Client_Updated__c = true; updateValues = true; } } } if(updateValues){ update mapofInc.values(); } }
I have updated your test class.
Please use the below test class :
Let me know if you have any issues in it.
Thanks,
Abhishek
Hi lilranger,
You are getting error because you are inserting four times in one test method .Basically if you wil insert or update like this your trigger wil execute per dml once .
If you want to test with bulk records you need to create record with for loop and needs to do tthe DML with list of records .
Also in your test class SeeAllData=true is not required here only if you want to query the Database record then you need this .
I don't think update statement is requird in test class .
Try with below code it will help. Let me know if it helps !!
Thanks
Manoj
for me, this thread solution worked https://salesforce.stackexchange.com/questions/164931/is-there-a-way-to-call-javascript-after-action-on-visualforce-page
with regards
https://kodi.software/download/ https://messenger.red/ https://hotstar.onl/