salesforce如何达到75%的顶点测试

salesforce如何达到75%的顶点测试,salesforce,Salesforce,我在71%,4行代码不能在测试中运行的某些原因。 当我在Salesforce中测试自己时,它可以工作(这些代码行正在运行)。 如何让这些代码行在测试中运行 线路未运行,以秒为循环 nextId=Integer.Valueof(c.next\u id\u\c) 线路未运行,在第三个for循环中 btnRecord.next\u id\u c=newid+1; btnRecord.last_id_uc=newId btnRecord.last_assigned_starting_id__c

我在71%,4行代码不能在测试中运行的某些原因。 当我在Salesforce中测试自己时,它可以工作(这些代码行正在运行)。 如何让这些代码行在测试中运行

  • 线路未运行,以秒为循环 nextId=Integer.Valueof(c.next\u id\u\c)

  • 线路未运行,在第三个for循环中 btnRecord.next\u id\u c=newid+1; btnRecord.last_id_uc=newId

        btnRecord.last_assigned_starting_id__c = nextId;
        btnRecord.last_assigned_ending_id__c = newId;
    
  • 下面是我的代码:

    trigger getNextId on tracking__c (before insert, before update) {
    
    Integer newId;
    Integer lastId;
    Integer nextId;
    
    newId=0;
    lastId=0;
    nextId =0;
    
    
    
    //add the total accounts to the last_id
    for (tracking__c bt: Trigger.new) {
    
        //get the next id
        List<tracking_next_id__c> btnxtid = [SELECT  next_id__c FROM tracking_next_id__c];
    
        for (tracking_next_id__c c : btnxtid )
        {
           nextId=Integer.Valueof(c.next_id__c);
        }
    
    
        newId = Integer.Valueof(bt.total_account__c) + nextId;
    
        bt.starting_id__c = nextId;
        bt.ending_id__c = newId;
    
        tracking_next_id__c[] nextIdToUpdate = [SELECT last_id__c, next_id__c, last_assigned_starting_id__c, last_assigned_ending_id__c FROM tracking_next_id__c];
        for(tracking_next_id__c btnRecord : nextIdToUpdate ){
    
            btnRecord.next_id__c = newid + 1;
            btnRecord.last_id__c = newId;
    
            btnRecord.last_assigned_starting_id__c = nextId;
            btnRecord.last_assigned_ending_id__c = newId;
    
        }
    
        update nextIdToUpdate ;
    
       }
       }
    
    在跟踪时触发getNextId(插入前、更新前){
    整数newId;
    整数lastId;
    整数nextId;
    newId=0;
    lastId=0;
    nextId=0;
    //将总帐户添加到最后一个\u id
    用于(跟踪:Trigger.new){
    //获取下一个id
    列表btnxtid=[从跟踪中选择下一个\u id\u c];
    用于(跟踪下一个\u id\u c:btnxtid)
    {
    nextId=Integer.Valueof(c.next\u id\u\c);
    }
    newId=整数.Valueof(bt.total\u account\u c)+nextId;
    bt.starting_id__c=nextId;
    bt.ending_id_uc=newId;
    跟踪下一个id\uuu c[]下一个id\uu更新=[从跟踪下一个id\uu c中选择最后一个id\uu c、下一个id\uu c、最后一个分配的id\uU开始的id\uU c、最后一个分配的id\uU结束的id\uU c];
    用于(跟踪下一个id记录:下一个更新){
    btnRecord.next\u id\u c=newid+1;
    btnRecord.last_id_uc=newId;
    btnRecord.last_assigned_start_id__c=nextId;
    btnRecord.last_assigned_ending_id_uuc=newId;
    }
    更新nextittoupdate;
    }
    }
    
    @isTest
    私有类GetNextId测试{
    静态测试方法void validateOnInsert(){
    跟踪c b=新跟踪c(总账户c=整数。值(99));
    系统调试('插入前:'+b.总计\科目\ c);
    插入b;
    系统调试('插入后:'+b.总计\科目\ c);
    列表customObjectList=
    [从跟踪中选择合计科目];
    用于(投标跟踪联系人:customObjectList){
    ont.账户总额c=5;
    }
    更新customObjectList;
    }
    }
    
    @isTest
    私有类GetNextId测试{
    静态测试方法void validateOnInsert(){
    跟踪c b=新跟踪c(总账户c=整数。值(99));
    系统调试('插入前:'+b.总计\科目\ c);
    插入b;
    系统调试('插入后:'+b.总计\科目\ c);
    列表customObjectList=
    [从跟踪中选择合计科目];
    用于(投标跟踪联系人:customObjectList){
    ont.账户总额c=5;
    }
    更新customObjectList;
    }
    }
    
    添加了@isTest(见alldata=true),并将其移动到100%

    添加了@isTest(见alldata=true),并将其移动到100%

    即使使用seeAllData=true增加了测试覆盖率,但除非确实需要,否则使用seeAllData不是最佳实践。有关详细信息,请查看博客

    增加覆盖率的另一种方法是创建用于跟踪下一个id对象的测试数据

        @isTest
        private class getNextIdTest {
        static testMethod void validateOnInsert(){
            tracking_next_id__c c = new tracking_next_id__c(next_id__c='Your next_id', 
                    last_id__c='Your last_id', last_assigned_starting_id__c='Your last_assigned_starting_id', 
                    last_assigned_ending_id__c='last_assigned_ending_id');
            insert c;
            tracking__c b = new tracking__c(total_account__c=Integer.Valueof(99));
            System.debug('before insert : ' + b.total_account__c);
            insert b;
            System.debug('after insert : ' + b.total_account__c);
            List<tracking__c> customObjectList =
            [SELECT total_account__c FROM tracking__c ];
            for(bid_tracking__c ont : customObjectList){
                ont.total_account__c = 5;
            }
            update customObjectList;
        }
    }
    

    只是一个观察,最好避免FOR循环中的SOQL查询,以避免运行时异常(101:太多SOQL查询)

    即使使用seeAllData=true增加了测试覆盖率,但除非确实需要,否则使用seeAllData不是最佳实践。有关详细信息,请查看博客

    增加覆盖率的另一种方法是创建用于跟踪下一个id对象的测试数据

        @isTest
        private class getNextIdTest {
        static testMethod void validateOnInsert(){
            tracking_next_id__c c = new tracking_next_id__c(next_id__c='Your next_id', 
                    last_id__c='Your last_id', last_assigned_starting_id__c='Your last_assigned_starting_id', 
                    last_assigned_ending_id__c='last_assigned_ending_id');
            insert c;
            tracking__c b = new tracking__c(total_account__c=Integer.Valueof(99));
            System.debug('before insert : ' + b.total_account__c);
            insert b;
            System.debug('after insert : ' + b.total_account__c);
            List<tracking__c> customObjectList =
            [SELECT total_account__c FROM tracking__c ];
            for(bid_tracking__c ont : customObjectList){
                ont.total_account__c = 5;
            }
            update customObjectList;
        }
    }
    
    只是一个观察,最好避免FOR循环中的SOQL查询,以避免运行时异常(101:SOQL查询太多

        tracking_next_id__c c = new tracking_next_id__c(next_id__c='Your next_id', 
                last_id__c='Your last_id', last_assigned_starting_id__c='Your last_assigned_starting_id', 
                last_assigned_ending_id__c='last_assigned_ending_id');
        insert c;