如何为salesforce ConnectApi.FeedElement编写测试函数

时间:2017-06-15 09:05:27

标签: salesforce apex

这是我的代码

public class ChatterFunction{

public ChatterFunction(){
    LIST<ISSUE__C> issID = [SELECT Id, Name FROM ISSUE__C];
    for(ISSUE__C i : issID){
        postfeed(i.Id);
    }
}

public static void postfeed(String iss){
      ConnectApi.FeedItemInput feedItemInput = new ConnectApi.FeedItemInput();
      ConnectApi.MentionSegmentInput mentionSegmentInput = new ConnectApi.MentionSegmentInput();
      ConnectApi.MessageBodyInput messageBodyInput = new ConnectApi.MessageBodyInput();
      ConnectApi.TextSegmentInput textSegmentInput = new ConnectApi.TextSegmentInput();

      messageBodyInput.messageSegments = new List<ConnectApi.MessageSegmentInput>();


      mentionSegmentInput.id = '00528045147FTed';
      messageBodyInput.messageSegments.add(mentionSegmentInput);

      textSegmentInput.text = 'Something';
      messageBodyInput.messageSegments.add(textSegmentInput);

      feedItemInput.body = messageBodyInput;
      feedItemInput.feedElementType = ConnectApi.FeedElementType.FeedItem;

      feedItemInput.subjectId = iss;

      ConnectApi.FeedElement feedElement = ConnectApi.ChatterFeeds.postFeedElement(null,feedItemInput );
}

}

我尝试用代码

测试它
@IsTest(SeeAllData=true) public static void testpostfeed() {
System.assertEquals(postfeed('a000l0013315hgr'),null);
}

但它显示错误消息:方法不存在或签名不正确:postfeed(String)

我不知道为什么它不存在....

1 个答案:

答案 0 :(得分:0)

你的方法是静态的,所以你需要像这样调用它

System.assertEquals(ChatterFunction.postfeed('...'), null);