I am callling the SOQL query through REST API from php. I am searching for the phone number using the below SOQL query. I want to trim the mobilephone in where clause. I tried MobilePhone.trim() and trim(MobilePhone) it's not working. How can I do it?
Select FirstName FROM Contact WHERE MobilePhone = '04123456789'
Thanks.
There is no ability to use 'trim' function in 'where' condition of SOQL.
Related
Background: I need access account records in the apex class where name contains %
For example, the query should return below accounts
abcd10%
cdcd40%abcd
10%volume
When I execute the below query I am getting results in the workbench
select id, name from Account where Name LIKE '%\%%'
the same query If I execute in Anonymous window/apex execute getting no results.
List accList = [select id,name from Account where Name LIKE '%\%%'];
system.debug('accList :::'+accList.size());
If we observe the below image, it is appending extra / in the query and giving wrong results.
Can you please help me how to resolve this?
16:00:21:002 SOQL_EXECUTE_BEGIN [1]|Aggregations:0|SELECT id, name FROM Account WHERE Name LIKE '%\%%'
You could use a bind variable or dynamic SOQL.
String searchText = '%\\%%';
List<Account> accs = [SELECT Id, Name
FROM Account
WHERE Name LIKE :searchText];
System.debug(accs.size());
System.debug(accs);
// Or in dynamic query (looks bit crazier because ' has to be escaped too)
List<Account> accs2 = Database.query('SELECT Id, Name FROM Account WHERE Name LIKE \'%\\%%\'');
System.debug(accs2);
I wrote below query to fetch data from salesforce but getting error like "Unknown error parsing query"
select Email,Id from contact where Email in (select b.Email from contact as b group by b.Email having count(b.id) < 2 limit 1000)
inner query alone retrieving the set of mail Ids, please suggest.
Are you sure the issue is not related with the query / organisation ?
Using SOQL workbench --> https://workbench.developerforce.com
and getting this error:
MALFORMED_QUERY:
(select b.Email from contact as b group by b.Email having count(b.id)
^
ERROR at Row:1:Column:78
expecting a right parentheses, found 'group'
You can first check your query on Salesforce using developer console if its working or not.
If its returning required result in Salesforce then it will work in Mulesoft as well.
I want to execute query in my yii2 application. I'm using PostgreSQl. There is a table called list inside the user schema. If I try to build any query it returns 1. My code is here:
$numUsers = Yii::$app->db->createCommand('
SELECT COUNT(*) FROM "user"."list"
')->execute();
Please show me my mistake in the query above.
This is not related to the DB type in Yii2 if you want the result of a single value you should use queryScalar() instead of execute()
$numUsers = Yii::$app->db->createCommand('
SELECT COUNT(*) FROM "user"."list" ')->queryScalar();
I use this select query and i am not getting what's the wrong with this.
Select Id,Contact.FirstName,Contact.LastName,Contact.Title,Contact.Department,Contact.Birthdate,
Contact.Phone,Contact.HomePhone,Contact.MobilePhone,Contact.OtherPhone,Contact.Fax,Contact.Email,Contact.MailingStreet,
Contact.MailingCity,Contact.MailingState,Contact.MailingCountry,Contact.MailingPostalCode,Contact.OtherStreet,
Contact.OtherCity,Contact.OtherState,Contact.OtherCountry,Contact.OtherPostalCode,Contact.Description,Contact.Account.Name From Contact where strcmp('%#',Id) = -1",lastcontactId
You need to generate a query that uses =, e.g.
select name from contact where id='005123123123123123'
so, you can use this to generate the query.
NSString *query = [NSString stringWithFormat:#"select name,etc from contact where id='%#'", lastContactId];
Here's the SOQL docs which has more examples.
And if you're trying to do paging, you should just run the entire query and use query/queryMore to page through the results.
My query in HQL is basically:
select functionA(a, :paramA), functionB(b, :paramB), functionC(c, :paramC), sum(d)
from tableA
groupby by functionA(a, :paramA), functionB(b, :paramB), functionC(c, :paramC)
However this gets turned into SQL of
select functionA(a, #param0), functionB(b, #param1), functionC(c, #param2), sum(d)
from tableA
groupby by functionA(a, #param3), functionB(b, #param4), functionC(c, #param5)
Now obviously this is going to throw a 'blah' is invalid in the select list because.... error as the group by clause doesn't match the select clause. I'm about to change this to a string format so I can get on with some productive work but if anyone has the answer as to why NHibernate will not reuse the same named query input the 2 times it is used that would be much appreciated.
A similar question seems to have been asked here with no real answer either.
This has been solved in NHibernate 3.0.0.Alpha1. You can get it here