• Bailey Carlson (CRMCulture)
  • NEWBIE
  • 5 Points
  • Member since 2014
  • Product Architect
  • CRMCulture

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Can anyone explain this behavior. I'm seeing a very significant performance difference between the two methods of writing a query in APEX,
 
List<sObject> contacts = [select Name from Contact limit 100]; // Static SOQL
Database.QueryLocator query = Database.getQueryLocator('select Name from Contact limit 100'); // Dynamic SOQL
Running profiler on the two lines of code in the Developer console reveals that the second query takes many orders of magnitude longer to run but returns only one row. It also indicates that the SOQL without the limit is being executed although only the limited number of rows are returned.

16:20:52.026 (26387500)|SOQL_EXECUTE_BEGIN|[1]|Aggregations:0|select Name from Contact limit 100
16:20:52.026 (26398954)|LIMIT_USAGE|[1]|SOQL|1|100
16:20:52.026 (26403155)|LIMIT_USAGE|[1]|AGGS|0|300
16:20:52.034 (34778605)|SOQL_EXECUTE_END|[1]|Rows:100
16:20:52.034 (34788820)|LIMIT_USAGE|[1]|SOQL_ROWS|100|50000
AnonymousBlock: line 1, column 1: [select Name from Contact limit 100]: executed 1 time in 9 ms

vs.

16:20:52.037 (37114365)|SOQL_EXECUTE_BEGIN|[2]|Aggregations:0|select Name from Contact 
16:20:52.037 (37123249)|LIMIT_USAGE|[2]|SOQL|2|100
16:20:52.037 (37127604)|LIMIT_USAGE|[2]|AGGS|0|300
16:20:52.294 (294504152)|SOQL_EXECUTE_END|[2]|Rows:100
16:20:52.294 (294522076)|LIMIT_USAGE|[2]|QUERY_LOCATOR_SOQL_ROWS|100|10000
AnonymousBlock: line 2, column 1: Database.getQueryLocator(String): executed 1 time in 258 ms

Notice the differences between the query are logged with the limit vs without the limit keyword and the difference in query times. It alarms me to think that the QueryLocator may be running the query without any limit in all cases! I prefer to use the QueryLocator method because I would like to pass it to the StandardSetController so that it can handle paging for me (it is limited to 10000 records whereas limit/offset cannot go beyond 2000). Note that the QueryLocator is still more performant than running the query without any limit so I don't really have an explaination for what is happening. If anyone has any insight on this I would greatly appreciate.


I am trying to use the metadata webservice API in order to determine which columns are on List Views and Search Layouts for a custom or out of box object. However, the response I get from the web service has the column names in an unusual format like this,

<listViews>
	<fullName>crmc_grid__AllContacts</fullName>
	<columns>ACCOUNT.NAME</columns>
	<columns>CONTACT.FIRST_NAME</columns>
	<columns>CONTACT.LAST_NAME</columns>
	<columns>CONTACT.ADDRESS2_STATE</columns>
	<columns>CONTACT.ADDRESS2_COUNTRY</columns>
	<columns>CONTACT.REPORTS_TO.NAME</columns>
	<columns>CONTACT.ADDRESS1_CITY</columns>
	<columns>CONTACT.EMAIL</columns>
	<columns>crmc_grid__Level__c</columns>
	<filterScope>Everything</filterScope>
	<label>All Contacts</label>
</listViews>
My question is how can I then use these a-typical column names to reliably and generically detect which SOQL fields are being displayed? In most cases it seems like removing the hyphens would translate to the SOQL schema name, however there is no Address1 or Address2 fields on the Contact table and they correspond to the Mailing and the Other address instead. Is there some other API for mapping these field names to field metadata or schema names? If this can't be done then what usefulness is there to the ListView metadata?

Thanks,
Bailey