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.

  • 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 Mar 19 '18 at 16:00
  • That query works in my sandbox? – Kasper Mar 19 '18 at 16:06
  • Is the query running in a with sharing class? – David Reed Mar 19 '18 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 Mar 19 '18 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 Mar 22 '18 at 9:00
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.

  • Nice catch pal. Everyone literally missed it. – Pranay Jaiswal Mar 23 '18 at 9:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.