1

I have account name as XYZ®Test’s. I dont want duplicate records so when i add new account I check if it already exists using an SOQL query in apex.

Select id from Account where Name='XYZ®Test’s'

It does not return any result and allows to create duplicate whereas I want to prevent that. I cannot get rid of the registered symbol.

Also I tried adding an external Id field which has the same value to prevent duplicate but it still allows to create duplicate accounts with that symbol.

9
  • 3
    i don't see this issue. can you put more details, your complete code etc. You might have issue at some other place.
    – Himanshu
    Commented Mar 19, 2018 at 16:00
  • That query works in my sandbox?
    – Kasper
    Commented Mar 19, 2018 at 16:06
  • Is the query running in a with sharing class?
    – David Reed
    Commented Mar 19, 2018 at 17:03
  • 1
    You should probably use built-in duplicate management, rather than writing your own implementation of it in Apex. help.salesforce.com/…
    – Mark Pond
    Commented Mar 19, 2018 at 18:20
  • @MarkPond Actually I have few records coming from external system and I check the name and update if it already exists else create new. In this case it is always creating new because it does not consider string with registered symbol
    – snehakem
    Commented Mar 22, 2018 at 9:00

1 Answer 1

3

Salesforce thinks that your query ends at the first closing quote. If you escape that quote than your query will work. This should work for you:

SELECT Id FROM Account WHERE Name = 'XYZ®Test\'s'

You can read more about this at: https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_quotedstringescapes.htm

By the way. Your current query actually works. That is because you used this ` instead of ' as your second quotation mark.

1
  • Nice catch pal. Everyone literally missed it. Commented Mar 23, 2018 at 9:17

You must log in to answer this question.

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