+ Start a Discussion
sumanth v 7sumanth v 7 

REST API String parse Issue

If i give hard code the value as below 
String toolingendpoint ='https://xxxxxxx.xxxxxx.com/sap/opu/odata/sap/xxxx_xxx_xxx/xxxx_xx?mat_num=\'*1160\'&sap-client=300';[1160 is hardcode value here]    able to retrieve data. But when i try as below unable to retieve

String toolingendpoint ='https://xxxxxxx.xxxxxx.com/sap/opu/odata/sap/xxxx_xxx_xxx/xxxx_xx?mat_num=\'*searchstring\'&sap-client=300'; [searchstring the value comes from VF page]. 

There is some mistake with '\' i am doing here. Please help.
SandhyaSandhya (Salesforce Developers) 
Hi Sumanth, 

When You are using string varaible in soql query you need to use + sign.

For example
String field = 'fieldx__c';
Strign soqlQuery = 'select Id,'+field+',Name from object__c';
object__c obj = database.query(soqlQuery);

Try this

Please refer below post for similar discussion.

Always try to print your query through system.debug  so that you will be able to find if the query is formed properly.

Hope this helps you!

Please mark it  as Best Answer if my reply was helpful. It will make it available for other as the proper solution. 
Thanks and Regards

sumanth v 7sumanth v 7
Hi Sandhya,

I solved this morning. You are right!
Thanks for your reply. 
SandhyaSandhya (Salesforce Developers) 
Ok please mark it as solved choosing BestAnswer so that it will be removed from the unanswered queue, and also it will make available for others as a proper solution.

Thanks and Regards