如何为下面的代码编写Test类

时间:2019-05-10 08:09:25

标签: salesforce salesforce-lightning

public List<HistoryTimelineObject> processTimelineItem(id recordId, Integer pageNo, Integer pageSize){
    List<HistoryTimelineObject> wrappedCase = new List<HistoryTimelineObject>();

    List<Case> t = [SELECT Id, Subject, AccountId, CreatedDate, CreatedBy.Name
    FROM   Case
    WHERE  Applicant__c = :recordId
    LIMIT :pageSize
    OFFSET :pageNo];
    if(t != null){
        for(Integer i = 0, CaseSize = t.size(); i < CaseSize; i++){
            wrappedCase.add(new HistoryTimelineObject().setActor(t[i].CreatedBy.Name)
                    .setHeader(t[i].Subject)
                    .setDate(t[i].CreatedDate.format())
                    .setIconName('standard:case')
                    .setIconColour('put the colour in here'));

        }
    }

    return wrappedCase;
}

1 个答案:

答案 0 :(得分:0)

您必须创建一个Case对象并将其插入测试类方法中。从测试类方法中调用上述方法。确保插入的大小写值和您传递给上述方法的参数中传递的数据相同。 有关测试课程的更多参考, [https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm]