+ Start a Discussion
Hari G SHari G S 

Trim Function in SOQL




Is there any trim function in SOQL? Please help.


Thanks and Regards

Hari G S


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:-




Hope this helps...


Let me try:


string tstring = 'john ';

tstsring = tstring.trim();

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


Hari G SHari G S



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.






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.



Ankit Arora

Blog | Facebook | Blog Page