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
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
'https://xxxxxxx.xxxxxx.com/sap/opu/odata/sap/xxxx_xxx_xxx/xxxx_xx?mat_num=\'+searchstring+'\&sap-client=300';


Please refer below post for similar discussion.

https://developer.salesforce.com/forums/?id=906F000000093fyIAA
 
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
Sandhya

 
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
Sandhya