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
Hari G SHari G S 

Trim Function in SOQL

 

Hi,

 

Is there any trim function in SOQL? Please help.

 

Thanks and Regards

Hari G S

IspitaIspita

Trim functions are available for string 

 

trim StringReturns a String that no longer contains any white space characters, including leading and trailing spaces, tabs, newline characters, and so on

here is the link for that:-

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_string.htm

 

Hope this helps...

Teach_me_howTeach_me_how

Let me try:

 

string tstring = 'john ';

tstsring = tstring.trim();

Contact cont1 = [Select id From Contact Where name=:tstring];

 

Hari G SHari G S

Hi

 

Thanks for the reply

 

But i want to get the db value trimmed.

 

Example, i may have two records say "Testing" and Testing ";

 

using the query   Select id form Account where name='Testing' i will get only "Testing" record. But i want to use something like this

 

Select id form Account where name.trim()='Testing' to get both records.

 

Thanks

Hari

 

 

Ankit AroraAnkit Arora

This should not be a case when you have values "Testing" and "Testing ", but if you have some values like this then you can use % like this

 

Select id form Account where name like 'Testing%'

 

It will return you all the records which have name starting with "Testing".

 

If this is not what you want then there is a workaround (bit long)

 

List<Account> accLst = [select id,name from account] ;
List<Account> yourFinalList = new List<Account>() ;
for(Account acc : accLst)
{
      if(acc.name.Trim().toLowerCase() == 'testing')
               yourFinalList.add(acc) ;
}

 I must say this is not the best way so go with the first approach.

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page