I have a very basic retrieval of a Salesforce record based on email address in AMPScript that works 99.9% of the time
SET @retrieveContact = RetrieveSalesforceObjects('Contact', 'Id,Email', 'Email', '=', @email)
However, today I discovered that if someone inputs an email address that has an apostrophe, RetrieveSalesforceObjects will crash. This is because AMPScript puts single quote rather than double quotes around variable strings. Here is the error that returns when someone submits an email address with an apostrophe (this is for a form). I am modifying the email address for her privacy.
{"message":"Call to retrieve records for salesforceobject Contact failed! Error in the application.
API Fault: Salesforce.com Fault thrown.
Exception Type:MalformedQueryFault
Exception Code:MALFORMED_QUERY
Exception Message:
Contact WHERE Email = 'firstname.o'[email protected]'
^
ERROR at Row:1:Column:53
unexpected token: bryant
At row:1 and column: 53","description":"ExactTarget.OMM.FunctionExecutionException: Call to retrieve records for salesforceobject Contact failed! Error in the application.
API Fault: Salesforce.com Fault thrown.
Exception Type:MalformedQueryFault
Exception Code:MALFORMED_QUERY
Exception Message:
Contact WHERE Email = 'firstname.o'[email protected]'
^
ERROR at Row:1:Column:53
unexpected token: bryant
At row:1 and column: 53
Error Code: RETRIEVESFOJBECTS_FUNC_ERROR
- from Jint"}
I have been trying to come up with a resolution to this issue but my only idea so far has been to just force email validation on all forms that leverage AMPScript to not accept email addresses with apostrophes. However, I would ideally like to find a workaround that allows email addresses with apostrophes.