i am trying to test a trigger my trigger code is

trigger PostFeedsToTimeLine on FeedItem (after insert) {
Map<String,String> contentMap = new Map<String,String>{'Object' =>'FeedItem','Content' =>'Body'};
if(Trigger.new.size() > 5){
BatchPublishTimeLine publishBatch = new BatchPublishTimeLine(Trigger.new,contentMap);
else GMirrorUtil.createTimeLine(Trigger.new, contentMap);

batch will always get created if size is greater than 5 but when size is greater than 5 two batch will get executed what to do.in batch i am calling GMirrorUtil.createTimeLine which is making two callouts thats why this 5 limit .what to do in this case ?? because maximum 5 batch can be queued thats why if possible i try to make it without batch but in cases when more than 5 then i execute it using Batch.


I think your best bet here is to just change the logic by using Test.IsRunningTest(). If that's true then pass in a new list with just one entry to the batch itself:

BatchPublishTimeLine publishBatch = new BatchPublishTimeLine(Test.IsRunningTest() ? new List<FeedItem>{Trigger.new[0]} : Trigger.new),contentMap);

I'm using the ternary if operator so that it's still one line of code and as such will prevent a missed line of coverage.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.