Find your content:

Search form

You are here

Test Coverage For Page parameters is not covering

 
Share
    public with sharing class LeadEventCreation {

    public PageReference doSave() {
        insert objL;
        objL.recordTypeId = apexpages.currentPage().getparameters().get('id');// these lines are not covering showing in red colour
        update objL;                                                          // these lines are not covering showing in red colour

        objE.whoId = objL.id;                                                 // these lines are not covering showing in red colour
        insert objE;                                                          // these lines are not covering showing in red colour
        return (new pagereference('/'+objL.id).setredirect(true));            // these lines are not covering showing in red colour
    }

    public Lead objL{get;set;}
    public Event objE{get;set;}
    public LeadEventCreation(){
        objL = new Lead();
        objE = new Event();
    }
}
    @isTest
    private static void mytestclass()
    {
        test.startTest();
            LeadEventCreation objLEC= new LeadEventCreation ();
                try{
                objLEC.doSave();
                }
                catch(exception e){}

                lead obj1= new lead();
                obj1.LastName= 'test name';
                try{
                insert obj1;
                }
                catch(exception e){}

                lead obj2= new lead();
                obj2.LastName= 'test name1';
                try{
                update obj2;
                }
                catch(exception e){}
                ApexPages.currentPage().getParameters().put('id','nytest');
        test.stopTest();
    }
}

Attribution to: rakesh

Possible Suggestion/Solution #1

It looks likely that the line:

        insert objL;

Is causing an exception and since you have:

        try{
        objLEC.doSave();
        }
        catch(exception e){}

You are swallowing the exception and not seeing what the issue is and the test is not going any further for doSave().

You would need to prevent the exception to allow doSave() to finish, i.e. ensure that the Lead is inserted correctly/without failure.


Attribution to: Phil Hawthorn
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/4853

My Block Status

My Block Content