顶点测试日志出错:common.apex.runtime.impl.ExecutionException:List没有用于赋值给SObject的行“

问题描述 投票:0回答:1

这是我试过的。我认为当我创建apex测试控制器并且我想将控制器的记录链接到我在测试类中创建的解决方案时,问题就出现在测试类的某个地方。

这是我在日志中发现的错误:“common.apex.runtime.impl.ExecutionException:List没有用于赋值给SObject的行”| 0x4888dd3c

apex class:

public with sharing class SolutionWrapper {
public ApexPages.StandardSetController controller;
public Opportunity opp{get; set;}
public Solutions__c oppId{get; set;}
public Solutions__c sol{get; set;}
public Solutions__c solution{get; set;}
public Account acc{get; set;}

public SolutionWrapper(ApexPages.StandardSetController controller) {
    try{
        solution = new Solutions__c();
        solution = (Solutions__c)controller.getRecord();
        if(solution.Id != null){
            oppId = [SELECT id, Solutions__c.Opportunity__c 
                FROM Solutions__c
            WHERE id =: solution.Id
            LIMIT 1];

            opp = [Select id,Name, AccountId, CurrencyIsoCode  from 
                     Opportunity where id =: oppId.Opportunity__c  LIMIT:1];
        }

        if(opp.id !=null){
            sol = [SELECT id,Name, Mail_Merge_Id__c,Solution_Country__c, Solutions__c.Opportunity__c 
        FROM Solutions__c
        WHERE Solutions__c.Opportunity__c =: opp.id
        LIMIT 1];
             acc = [Select id,Name,Country__c from 
                     Account where id=:opp.AccountId LIMIT: 1];
        }


    }
    catch(Exception e){
        ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR,e.getMessage()));
    }

}

}

这是我的测试课

顶点测试类:

@isTest 
public class SolutionWrapperTest {

     static testMethod void testMethodOpp(){
         Account acc = new Account(Name='test', Country__c='test'); 
          insert acc; 
         Opportunity opp = new Opportunity(Name='test', AccountId=acc.id, CurrencyIsoCode='GBP', StageName = 'Good',
          CloseDate =  date.today());
         insert opp;
         Solutions__c sol = new Solutions__c( Opportunity__c= opp.id, CurrencyIsoCode='GBP');       
           insert sol;          

         List<Solutions__c> listSol = new List<Solutions__c>();
         listSol.add(sol);
         PageReference pageRef = Page.NewVisualForcePage;
         Test.setCurrentPage(pageRef); 

        Test.startTest();
         ApexPages.StandardSetController stdController = new ApexPages.StandardSetController(listSol);
         SolutionWrapper testSolution = new SolutionWrapper(stdController);
        Test.stopTest();

        }


}
testing salesforce apex apex-code visualforce
1个回答
0
投票

解决方案ID与我在测试类中插入的解决方案ID不同。我在像Currency这样的字段上插入了一个虚拟值(eq'test')。之后我选择了基于货币而不是id的数据库。

© www.soinside.com 2019 - 2024. All rights reserved.