[SalesForce] Test Class for Visualforce page

I have a visual page controller with save() function. Inside the save() function, there is an insert object. However, when I write my test class, I am unable to query the inserted object.

controller snippet

public pageReference save() {

    insert opp;

    return pr;
}

test case

 @isTest
 private class standardOpptest {
     static testMethod void testStandardOpportunity(){
         //fill in data
        myextension.save(); //call the save method in controller

        Opportunity new_opp = [SELECT Prime_Function__c, 
                              FROM Opportunity ORDER BY CreatedDate DESC LIMIT 1 ];
    }

The query line gave me a

"System.QueryException: List has no rows for assignment to SObject"

exception.

Can anyone help?

Best Answer

Try replacing @isTest with @isTest(seeAllData = true)

Related Topic