Friday, December 09, 2016

System.UnsupportedOperationException: ConnectApi methods are not supported...


I am using ConnectorAPIHelper to post Chatter notification from apex code.When I run my apex test class it giving this exception :
System.UnsupportedOperationException: ConnectApi methods are not supported in data siloed tests. Please use @IsTest(SeeAllData=true).

It seems in order to cover the class that use ChatterApi, the test class need to be SeeAllData=true .

In my case, because I only have one line method that call ChatterApi , I think it's better use Test.isRunningTest instead of SeeAllData=true.


 public static void postChatter(){
     //exclude this from testing because in order to test ChatterApi ,we must set SeeAllData=true.
     //This class is test separately so it can be ignore for this testing.
     if(!Test.isRunningTest()){
          //send chatter notification
          ConnectApi.FeedItem fi = (ConnectApi.FeedItem)ConnectApiHelper.postFeedItemWithMentions(Network.getNetworkId(), 'me', 'Hi ,'+recipientChatter+ '-There has been an in Batch Job.Please check');
        }
    
    } 

More info please refer here .

No comments:

Post a Comment