function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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',;
    insert c;
Contact c2 = new Contact(FirstName='Jane',Lastname='Doe',;
    insert c2;
Opportunity o = new Opportunity(Name='Test Opportunity',, stagename='Confirmed Teaching/Class Schedule',Probability=0.95,;
    insert o;      
OpportunityContactRole ocr = new OpportunityContactRole (Opportunityid =,, role='Decision Maker', isPrimary=True) ;     
    insert ocr;  
OpportunityContactRole ocr2 = new OpportunityContactRole (Opportunityid =,, role='Decision Maker', isPrimary=False) ;     
    insert ocr2;  
Quote q = new Quote (Name='Test Demo',;
    insert q;
Quote_Contact__c qcc = new Quote_Contact__c (,;
    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.