1

When i execute this query through the developer console I get results

select parentid from CaseComment where commentbody LIKE '%glitches%'

but when I do the exact same query with apex I get no results.

string st = '\'%' + srchText + '%\'';
CaseComment[] ccids = [select parentid from CaseComment where commentbody LIKE :st];

When I examine the variable and write these to the debug log it looks fine but returns no results

What am I doing wrong?

1 Answer 1

1

Use this without escape characters:

string st = '%' + srchText + '%';
CaseComment[] ccids = [select parentid from CaseComment where commentbody LIKE :st];

In Debug log it will return like this:

[{"ParentId":"5007A000003eJQHQA2","Id":"00a7A000000Q38kQAC"}]
3
  • Ah it's a security issue on casecomment object for the portal user. Stink!. Thanks for your help though. When i ran it as me it works fine now. Thanks for your help Santanu
    – Ohmicron
    Feb 16, 2017 at 18:02
  • I mean community user
    – Ohmicron
    Feb 16, 2017 at 18:11
  • After I fixed the code like your suggestion I then discovered that the reason they saw no results as a community user is none of the comments with the search word in it where marked public. Once I made them public everything works fine. Thanks again Santanu
    – Ohmicron
    Feb 16, 2017 at 18:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .