逃生&SOQL 中的(与号) [英] Escaping & (ampersand) in SOQL

查看:89
本文介绍了逃生&SOQL 中的(与号)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这段代码可以在 Salesforce 上搜索数据:

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

代码:

$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));

错误:

mismatched character '&' expecting '}'

我尝试使用 preg_replacehtmlentities,我一直遇到同样的错误,我该怎么做才能搜索包含 &<的字符串/代码>?

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 &?

谢谢.

推荐答案

你需要一个斜线,像这样:FIND {A \&B}(顺便说一下,这是一个有效的 SOSL 搜索;))

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

滚动到 https:///developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_sosl_examples.htm 了解更多信息.

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.

不知道是否有内置的 php 函数可以为您执行此操作.最坏的情况是使用 str_replacepreg_replace 等创建您自己的实用程序.

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.

这篇关于逃生&amp;SOQL 中的(与号)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆