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
34213421 

Like Operator in SOQL System.QueryException: expecting a colon, found 'tempInput'

I am trying to use a string search in SOQL. I am getting error saying 

System.QueryException: expecting a colon, found 'tempInput'
string tempInput = '%' + 'GH' + '%';

       String qryStr = 'SELECT Id, Name';
 		qryStr += ', Receipt__c';
        qryStr += ', Class__c,'; 
        qryStr += ' FROM Line__c';
        qryStr += ' WHERE Receipt__r.Posted__c = true';
        qryStr += ' AND Receipt__r.Description__c like tempInput' ;
        qryStr += ' AND Receipt__r.OPayment__c = null';

 
GhanshyamChoudhariGhanshyamChoudhari
qryStr += ' Name like '+tempInput ;

 
Dushyant SonwarDushyant Sonwar
You missed a ":" colon when using variable in the query. 
string tempInput = '%' + 'GH' + '%';

       String qryStr = 'SELECT Id, Name';
 		qryStr += ', Receipt__c';
        qryStr += ', Class__c,'; 
        qryStr += ' FROM Line__c';
        qryStr += ' WHERE Receipt__r.Posted__c = true';
        qryStr += ' AND Receipt__r.Description__c like :tempInput' ;
        qryStr += ' AND Receipt__r.OPayment__c = null';