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
perumalvpsperumalvps 

Replace() in soql

Hi

 

 I have requirement to use replace() in soql query as like following code.

 

select Name from customobject where replace('custom_field','-','')='value'.

 

Any suggestions for replace() function in soql.

 

Thanks in Advance.

Ankit AroraAnkit Arora

No you can't use replace in query. You need to get the proper replaced value before using it in SOQL query.

 

Like if I need to search account with name "ttst" and provided value is "test" then we need to do something like this :

 

String str = 'test'.replace('e' , 't') ;
List<Account> accLst = [select id from account where name =: str]  ;

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

perumalvpsperumalvps

Hi Ankit_Arora

 

   Thanks for your reply.

 

  My constraint is to replace some characters of custom field which is already available in database and to compare with given string.

 

  The solution you have provided is to how replace the input string value. But i need solution to replace database field value and to compare in SELECT query.

 

Regards,

S.Perumalsamy

Ankit AroraAnkit Arora

No you can't compare two values in SOQL query directly. You need to use any field API and compare it with some value.

 

In your case you can create a formula field which will do all the logic and provide you the final result, and you can use that formula to compare with some value.

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page