Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is the code for a page launched from an Event. It links the Event to a custom object Business_trip__c via a junction object Trip_meeting__c using the Event's ID as a text key. I am having issue running the test - I think I am not properly setting the page and am returning the titular error "List has no rows for assignment to SObject" for the EventIdString query.

Class:

public class NewTripMeetingExtension {

    private ApexPages.StandardController sc;
    public trip_meeting__c TM {get;set;}
    public List <Event> EventId {get;set;}
    public String EventIdString {get;set;}
    public String EventReference {get;set;}

    public NewTripMeetingExtension (ApexPages.StandardController StandardController) {
        sc = standardController;

        EventIdString = (String)[select id from Event where Id=: (ApexPages.currentPage().getParameters().get('EventId'))].Id;
        Eventreference= [select subject from Event where Id=: (ApexPages.currentPage().getParameters().get('EventId'))].subject;
        TM = new Trip_meeting__c ();
        TM.Meeting__c=EventIdString;

    }

    public PageReference Cancel(){
        PageReference cancelUrl=new PageReference('/'+EventIdString);
        return cancelUrl;
    }

    public PageReference Save(){
        PageReference SaveUrl=new PageReference('/'+EventIdString);
        Trip_meeting__c TM1 = (trip_meeting__c)sc.GetRecord();
        TM1.Meeting__c=EventIdString;
        Database.insert(TM1, false);
        return SaveUrl;
    }


}

Test Code:

@isTest
public class testNewTripMeetingExtension {
     static testMethod void  testNewTripMeeting(){


        Account acc = new Account(Name='Abce');
        insert acc;

        Account a = new Account (name='Banson Quixotics');
        Insert a;

        Business_trip__c BT = new Business_trip__c (name='Name', Location__c='location', Start_date__c =System.today(), End_Date__c=System.today());
        insert BT;

        Event TestEvent = new Event ();
        TestEvent.subject='meeting subject';
        TestEvent.ActivityDate =date.today();
        TestEvent.ActivityDateTime = system.now();
        TestEvent.DurationInMinutes=12;
        TestEvent.Business_trip__c=BT.id;
        TestEvent.WhatId=a.id;
        TestEvent.Description='here are the notes in the field required to be there';
        inSert TestEvent;    

        Trip_meeting__c TM = new Trip_meeting__c();
        TM.Business_Trip__c=BT.id;
        Tm.Meeting__c = String.valueOf(TestEvent.id);
        Insert TM;

        PageReference pageRef = Page.NewTripMeetingEntry;   

         Test.setCurrentPage(pageRef);
         pageRef.getParameters().put('?EventId=',TestEvent.id);
         ApexPages.StandardController sc = new ApexPages.standardController(TestEvent);
         NewTripMeetingExtension  controller = new NewTripMeetingExtension(sc);

    }
}

Thanks

share|improve this question
up vote 1 down vote accepted

Change this line

pageRef.getParameters().put('?EventId=',TestEvent.id);

to

pageRef.getParameters().put('EventId',TestEvent.id);

You don't have to pass ?, = and & when setting.

share|improve this answer
    
thanks. happy that I got as far as i did – jaw999 Mar 28 at 18:16
pageRef.getParameters().put('?EventId=',TestEvent.id);

instead try this

ApexPages.currentPage().getParameters().put('EventId',TestEvent.id);

this will solve your issue..

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.