SOSL单引号问题

时间:2012-09-03 11:07:00

标签: salesforce apex-code

我对sosl有疑问。

这很好用:

List<List<SObject>> searchList = null;  
string startAddress = 'hello';  
searchList = Search.query('FIND \'' +startAddress + '\' IN ALL FIELDS RETURNING Account');

但是如果我写这样的话,它会给我一个错误:

List<List<SObject>> searchList = null;  
string startAddress = 'Tom\'s Towing and Recovery';  

searchList = Search.query('FIND \'' +startAddress + '\' IN ALL FIELDS RETURNING Account');  

Error : System.QueryException: line 1:507 mismatched character '<EOF>' expecting '''

请为此问题提出解决方案。 任何形式的帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

请像这样逃避输入:

string startAddress = string.escapeSingleQuotes( 'Tom\'s Towing and Recovery' );