You need to sign in to do that
Don't have an account?
TylerBrooks
FeedItem Test Class not giving proper coverage
Hey All,
I wrote a simple apex trigger to get Case Feed Items and after they're inserted create a new record which stores information for our Business analysts. The code works in my sandbox and does what I want it to do but when trying to create a test class I only get 18% coverage and I'm not sure how to adjust my test class to get the required code coverage.
TRIGGER:
TEST CLASS:
I wrote a simple apex trigger to get Case Feed Items and after they're inserted create a new record which stores information for our Business analysts. The code works in my sandbox and does what I want it to do but when trying to create a test class I only get 18% coverage and I'm not sure how to adjust my test class to get the required code coverage.
TRIGGER:
trigger CaseFeed on FeedItem (after insert) { List<Case> Cases = [SELECT Id, CaseNumber FROM Case]; for(case myCase : Cases) { for(FeedItem caseFeed : trigger.new) { if(caseFeed.ParentId == myCase.Id) { Case_History_and_Feed_Tracking__c chf = new Case_History_and_Feed_Tracking__c(); chf.Case__c = caseFeed.ParentId; chf.TSR__c = caseFeed.CreatedById; chf.Change_Made_Body__c = caseFeed.Body; insert chf; } } } }
TEST CLASS:
@isTest private class TestCaseFeed { @isTest static void InsertCaseFeed() { FeedItem caseFeed = new FeedItem(); caseFeed.Body= 'Testing my test class :D'; caseFeed.ParentId = '5002a000004TOCrAAO'; caseFeed.CreatedById = '0050y00000E1zyyAAB'; insert caseFeed; } }The lines of code in the trigger saying they get coverage is
List<Case> Cases = [SELECT Id, CaseNumber FROM Case]; for(case myCase : Cases)
All Answers