+ Start a Discussion

Test Class not working - assertion fails

This is driving me crazy.  It works in "real life" - meaning if I go to a record and try it myself it works but in my test class it insists that the assert for the search fails.  The code for the search in the controller itself is this:

    public void updateAvailableList() {
        // We dynamically build a query string and exclude items already in the shopping cart
        String qString = 'select Id, ContactId, OpportunityId from OpportunityContactRole where OpportunityId = \'' + theOpp.Id + '\'';
        // note that we are looking for the search string entered by the user in the First Name OR Last Name
        // modify this to search other fields if desired
            qString+= ' and (OpportunityContactRole.Contact.FirstName like \'%' + searchString + '%\' or OpportunityContactRole.Contact.LastName like \'%' + searchString + '%\')';


and my test class is saying the following - which is almost exactly the same as another test class and controller I have that does assert just fine.  Driving me crazy.


        // test search again, this time we will find something
        qCEE.searchString = c2.FirstName;



the c2.FirstName is part of my records created at the beginning of the test class as:

Account a=new Account(Name='Test Account');
    insert a;
Contact c = new Contact(FirstName='John',LastName='Doe', AccountID=a.id);
    insert c;
Contact c2 = new Contact(FirstName='Jane',Lastname='Doe',AccountID=a.id);
    insert c2;
Opportunity o = new Opportunity(Name='Test Opportunity',closedate=system.today(), stagename='Confirmed Teaching/Class Schedule',Probability=0.95, accountID=a.id);
    insert o;      
OpportunityContactRole ocr = new OpportunityContactRole (Opportunityid = o.id, Contactid=c.id, role='Decision Maker', isPrimary=True) ;     
    insert ocr;  
OpportunityContactRole ocr2 = new OpportunityContactRole (Opportunityid = o.id, Contactid=c2.id, role='Decision Maker', isPrimary=False) ;     
    insert ocr2;  
Quote q = new Quote (Name='Test Demo', Opportunityid=o.id);
    insert q;
Quote_Contact__c qcc = new Quote_Contact__c (Adoption_Agreement__c=q.id, contact__c=c.id);
    insert qcc;



If anyone sees what I'm doing wrong that would be awesome.  I can't remove the assertion because then the next part fails as well.