0

我是 Apex 新手 需要 Apex 测试课程的帮助。控制器类工作得很好,但我无法找到一种方法将其复制到测试类中而不会出现错误“列表没有分配给 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
4

1 回答 1

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];
于 2014-10-08T17:19:17.773 回答