2014-10-08 67 views
0

我是Apex新手需要Apex测试类的帮助。该控制器类的伟大工程,但我不能找到一种方法,将其复制到测试课,而不会出现错误“列表中包含了用于分配的sObject无行” 下面是实际的控制器类:列表中没有行分配给SObject测试类错误

public with sharing class GoogleMap_Meeting_Controller { 

    public List<Meeting__c> MeetingsList {get;set;} 
    public List<Meeting__c> MeetingsList2 {get;set;} 

    public GoogleMap_Meeting_Controller() { 

     Id id = ApexPages.currentPage().getParameters().get('id'); 
     MeetingsList = [SELECT Id, Name, Group__r.Id, Meeting_Date__c, GPS_Meeting_Location__Latitude__s, GPS_Meeting_Location__Longitude__s FROM Meeting__c WHERE Group__r.Id =:id ORDER BY Meeting_Date__c DESC LIMIT 10 OFFSET 1]; 
     MeetingsList2 =[SELECT Id, Name, Group__r.Id, Meeting_Date__c, GPS_Meeting_Location__Latitude__s, GPS_Meeting_Location__Longitude__s FROM Meeting__c WHERE Group__r.Id =:id ORDER BY Meeting_Date__c DESC LIMIT 1]; 
    } // end constructor 
} // end class 

我的测试类;

public with sharing class GoogleMap_Meeting_Controller_Tester { 

    static testMethod void myTest() { 
     Meeting__c MeetingsList = new Meeting__c(); 
     Meeting__c MeetingsList2 = new Meeting__c(); 

     //Id id = ApexPages.currentPage().getParameters().get('id'); 
     MeetingsList = [SELECT Id, Name, Group__r.Id, Meeting_Date__c,  GPS_Meeting_Location__Latitude__s, GPS_Meeting_Location__Longitude__s FROM Meeting__c WHERE Group__r.Id ='a0Lc0000002zI9O' ORDER BY Meeting_Date__c DESC LIMIT 10 OFFSET 1]; 
     MeetingsList2 =[SELECT Id, Name, Group__r.Id, Meeting_Date__c, GPS_Meeting_Location__Latitude__s, GPS_Meeting_Location__Longitude__s FROM Meeting__c WHERE Group__r.Id ='a0Lc0000002zI9O' ORDER BY Meeting_Date__c DESC LIMIT 1]; 
    } // end constructor   
} // end class 

回答

0

而不是

MeetingsList = [SELECT Id, Name, Group__r.Id, Meeting_Date__c, GPS_Meeting_Location__Latitude__s, GPS_Meeting_Location__Longitude__s FROM Meeting__c WHERE Group__r.Id =:id ORDER BY Meeting_Date__c DESC LIMIT 10 OFFSET 1]; 
MeetingsList2 =[SELECT Id, Name, Group__r.Id, Meeting_Date__c, GPS_Meeting_Location__Latitude__s, GPS_Meeting_Location__Longitude__s FROM Meeting__c WHERE Group__r.Id =:id ORDER BY Meeting_Date__c DESC LIMIT 1]; 

使用

List< MeetingsList> = [SELECT Id, Name, Group__r.Id, Meeting_Date__c, GPS_Meeting_Location__Latitude__s, GPS_Meeting_Location__Longitude__s FROM Meeting__c WHERE Group__r.Id =:id ORDER BY Meeting_Date__c DESC LIMIT 10 OFFSET 1]; 
List< MeetingsList2> =[SELECT Id, Name, Group__r.Id, Meeting_Date__c, GPS_Meeting_Location__Latitude__s, GPS_Meeting_Location__Longitude__s FROM Meeting__c WHERE Group__r.Id =:id ORDER BY Meeting_Date__c DESC LIMIT 1]; 
+0

不要写 “版主请帮忙”。选择代码块并按下“Ctrl + K”。对于将来的任何问题,请随时访问像[旅舍](http://chat.meta.stackexchange.com/rooms/89/tavern-on-the-meta)等聊天室并询问。 – 2014-10-16 07:18:14

相关问题