4

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.

1 Answer 1

7

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 + '%\''));
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .