0

i'm an Apex newbie Need help with Apex test class. The controller class works great but I cant find a way to replicate it into a test class without the error "List has no rows for assignment to SObject" Here is the actual controller class:

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

My test 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
user2275344
  • 39
  • 3
  • 12
Rufus K.
  • 107
  • 1
  • 6

1 Answers1

0

Instead of

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];

use

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];
Infinite Recursion
  • 6,511
  • 28
  • 39
  • 51
Andrii Muzychuk
  • 1,151
  • 3
  • 20
  • 28
  • Don't write "Moderators please help". Select the code block and press `Ctrl+K`. For any issues in future, please feel free to visit a chat room like the [Tavern](http://chat.meta.stackexchange.com/rooms/89/tavern-on-the-meta) and ask. – Infinite Recursion Oct 16 '14 at 07:18