1

I am trying to create Dynamic Soql Query using Like Operator given as below:

String tempInput ='\'%' + inputValue2  + '%\'';

                      soqlRAD2 = soqlRAD2  + ' and BR_Opportunity__r.Account.name Like :'+tempInput ;   

But getting not able to format in properly and Getting Exception as below:

System.QueryException: Only variable references are allowed in dynamic SOQL/SOSL.

Please Help me on this..

Thanks in Advance.

4

In your case

String tempInput ='\'%' + inputValue2  + '%\'';

soqlRAD2 = soqlRAD2  + ' and BR_Opportunity__r.Account.name Like :'+tempInput ;  

Just remove colon :

like this

String tempInput ='\'%' + inputValue2  + '%\'';

soqlRAD2 = soqlRAD2  + ' and BR_Opportunity__r.Account.name Like '+tempInput ;  

Example

system.debug(Database.query('SELECT Id FROM Account WHERE Name like \'%test%\''));

With variable

String inputValue2 ='test';
system.debug(Database.query('SELECT Id FROM Account WHERE Name like \'%inputValue2%\''));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.