Escaping & (ampersand) in SOQL

旧城冷巷雨未停 提交于 2019-12-11 07:35:19

问题


I have this piece of code to search for data on Salesforce:

Code:

$campaign_name = 'A & B Campaign';  
$search = 'FIND {'.$campaign_name.'} IN NAME FIELDS RETURNING CAMPAIGN(ID)';
$searchResult = $mySforceConnection->search($search);
var_dump('$searchResult: ' . print_r($searchResult, true));

Error:

mismatched character '&' expecting '}'

I tried to use preg_replace, htmlentities, I keep getting the same error, what can I do to be able to search for strings containing &?

Thanks.


回答1:


You need a slash, like that: FIND {A \& B} (that's a valid SOSL search by the way ;))

Scroll to bottom of https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_sosl_examples.htm for more info.

No idea if there's a built-in php function that would do this for you. Worst case create your own utility function with str_replace, preg_replace etc.



来源:https://stackoverflow.com/questions/48541670/escaping-ampersand-in-soql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!