SOQL/SOSL: Using NOT LIKE
I’ve had to struggle to remember how to do this enough times that I think it’s worth documenting. Using the LIKE keyword to filter records in a SOQL or SOSL query is a great way to do searching using a...
View ArticleHow to Select Archived Tasks and Events in SOQL
I recently encountered an issued where I could see a Task from within Salesforce.com, but I could not select it with the API. After some further research, I realized that it was qualified as an...
View ArticleSQLForce: an option for Select Distinct in Salesforce
Today I was trying to get a list of distinct values in a field in Salesforce having a certain criteria. If SOQL supported ‘select distinct’, this could be accomplished quite trivially. Of course you...
View ArticleUsing Batch Apex with non-dynamic (static) SOQL
If you look at the Using Batch Apex guide in the developer docs, all of the examples use Dynamic SOQL, that is SOQL that can be constructed using a String, as in List<Account> accounts =...
View ArticleOnly Aggregate Expressions Use Field Aliasing
If you’ve ever come across the following error in a SOQL statement in Salesforce: Save error: only aggregate expressions use field aliasing, Force.com save problem The issue is that you forgot a comma...
View ArticleSystem.QueryException: List has no rows for assignment to SObject
I’ve run across this oddity a few times. When you construct a SOQL query thusly Account a = [select id from account where id = '01pL00000000XXX']; And if the ID returns no rows, instead of setting the...
View ArticleUsing SOQL Subquery to Count Child Records
Short post, just wanted to post a real world application of previous post I made, Subquerying in SOQL. I recently extended the Product2 object with an object that I would have LIKED to be a...
View ArticleSalesforce SOQL Subquery and Custom Objects with Apex
Recently I was dealing with attempting to query a custom object and also its child custom object using a subquery. The only place that the official Apex Language Reference mentions subqueries is in...
View Article