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
icemft1976icemft1976 

APEX variable in SOQL query ( Where ID = :[string] )

I'd like to use an APEX String variable to form the 'where ID =' clause of a SOQL Select statement

I am parsing a salesforce ID out of an email body text then feeding it into this query (which returns no rows):

... String caseNo = email.plainTextBody.substring(email.plainTextBody.indexOf('CaseId:'), email.plainTextBody.indexOf('<caseid>'));
//System.debug(caseNo);
Case caseToUpdate = [ select id, status, subject, description from Case where Id =  :caseNo limit 1];
...

Am I misunderstanding the 'ID = ' comparison behavior? When I debug, the runtime variable 'caseNo' is a valid ID.

Any suggestions?


Message Edited by icemft1976 on 05-06-2008 11:29 AM
icemft1976icemft1976
Haha - found it. This DOES work - I just had the wrong index set when I was parsing the email body.

I needed to shift 'right' since I was parsing  at the start of my delimiter, not the end...

wrong: 

String caseNo = email.plainTextBody.substring(email.plainTextBody.indexOf('CaseId:'), email.plainTextBody.indexOf('<caseid>'));

debug result: caseNo = 'CaseId:50030000004SyXX'

right:

String caseNo = email.plainTextBody.substring(email.plainTextBody.indexOf('CaseId:')+7, email.plainTextBody.indexOf('<caseid>'));
debug result: caseNo = '50030000004SyXX'
paul-lmipaul-lmi
i found using indexof for this to be "breakable" too much for my comfort.  if you're interested, i ended up achieving the same effect by putting :::{!case.id}::: at the bottom of emails going out, and then using a regex matcher to parse for it.

the bonus is that it's also much quicker to execute (i think).
sdavidowsdavidow
So, I think I'm attempting to do the same thing you guys are...which is mimick the email-to-case agent using APEX and email services. 

Instead of re-inventing the wheel, can you guys point me in the right/better direction?
Thanks.