I am using SalesForce SOAP Enterprise WSDL API in my C# application. What I came across is the need to use the SELECT query which includes REPLACE function. I tried Developer Console>>Query Editor by executing the following query, but it's giving me

Unknown error parsing query

Following is my query that I want to execute :

`SELECT Id, Name, HomePhone, MobilePhone, OtherPhone, office_phone__c.replace("-",""), phone_fax__c FROM Contact`

I also tried in the following way, but that's also giving me the same error.

`SELECT Id, Name, HomePhone, MobilePhone, OtherPhone, REPLACE(office_phone__c,'-',''), phone_fax__c FROM Contact `

As the query implies, I want to replace "-" in my office_phone__c field with "".

Has anyone used such type of query before. I would be very grateful if anybody can lead me in the right direction.


You cannot query like that.

Query with the normal office_phone__c field. Then when using the field value in your code replace the - with '' at that time.

  • You meant to say that SalesForce doesn't support replace function at all in the query? But what if I have to select many fields of these types. This is just a single example that I gave for ease of understanding. Actually my query contains around 5 to 6 such fields and I want to replace characters like (, ), - and ` `
    – YuDroid
    Dec 29 '14 at 6:37
  • There is no replace function that you can use directly in a SOQL query. You have first query the data and then manipulate it.
    – Sam
    Dec 29 '14 at 6:45

The SOQL language does not support any function like a "REPLACE" function. You best bet is to query for the data, and then later in your code, you can replace the values. An alternative is to use a forumula fields which replaces the value and you query the formula fields instead of the actual fields.

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.