Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
Hi,
Is there any trim function in SOQL? Please help.
Thanks and Regards
Hari G S
Trim functions are available for string
here is the link for that:-
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_string.htm
Hope this helps...
Let me try:
string tstring = 'john ';
tstsring = tstring.trim();
Contact cont1 = [Select id From Contact Where name=:tstring];
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
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
Trim functions are available for string
here is the link for that:-
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_string.htm
Hope this helps...
Let me try:
string tstring = 'john ';
tstsring = tstring.trim();
Contact cont1 = [Select id From Contact Where name=:tstring];
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
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)
I must say this is not the best way so go with the first approach.
Thanks
Ankit Arora
Blog | Facebook | Blog Page