Reply
Visitor
amonkey
Posts: 4
0
Accepted Solution

Database.getQueryLocator(String) truncates WHERE from Query String

I'm running a batchprocess that works except it does not use the where clause in the query. Is there some kind of pitfall that I should be aware of with Database.getQueryLocator and Where clauses?

 

Anybody...

Trusted Contributor
crop1645
Posts: 359
0

Re: Database.getQueryLocator(String) truncates WHERE from Query String

Do a system.debug to get the SOQL query and then paste it into Salesforce workbench or other tool to see if it looks right and returns what you expect. The Where clause works fine in batch apex

Eric
Visitor
amonkey
Posts: 4
0

Re: Database.getQueryLocator(String) truncates WHERE from Query String

When I check the logs it actually shows the WHERE clause as truncated:

 

17:50:59.076 (76328000)|USER_DEBUG|[39]|DEBUG|Within BatchProcesses start method
17:50:59.076 (76340000)|SYSTEM_METHOD_EXIT|[39]|System.debug(ANY)
17:50:59.076 (76372000)|SYSTEM_METHOD_ENTRY|[44]|System.debug(ANY)
17:50:59.076 (76394000)|USER_DEBUG|[44]|DEBUG|The query string is SELECT Customer_Status__c, Auto_Archived__c, LastActivityDate, Id, Has_Open_Activity__c, Prefers_to_Work_with_Associated_Agent__c, Status, FirstName, LastName, State, OwnerId, IsConverted FROM Lead WHERE IsConverted!=true AND (Customer_Status__c!='Contact Attempt 1' OR Customer_Status__c!='Contact Attempt 2')
17:50:59.076 (76407000)|SYSTEM_METHOD_EXIT|[44]|System.debug(ANY)
17:50:59.076 (76430000)|SYSTEM_METHOD_ENTRY|[45]|Database.getQueryLocator(String)
17:50:59.077 (77493000)|SOQL_EXECUTE_BEGIN|[45]|Aggregations:0|SELECT Customer_Status__c, Auto_Archived__c, LastActivityDate, Id, Has_Open_Activity__c, Farmers_Agent_Test_Lead__c, Prefers_to_Work_with_Associated_Agent__c, Status, FirstName, LastName, State, OwnerId, IsConverted FROM Lead 
17:50:59.191 (191179000)|SOQL_EXECUTE_END|[45]|Rows:9
17:50:59.191 (191250000)|SYSTEM_METHOD_EXIT|[45]|Database.getQueryLocator(String)
17:50:59.889 (306976000)|CUMULATIVE_LIMIT_USAGE
Trusted Contributor
crop1645
Posts: 359
0

Re: Database.getQueryLocator(String) truncates WHERE from Query String

What you are seeing is an artifact of the debug log Spring 13. The where clause is executing - I tried on my own data and it works fine

 

As an aside, I'm always telling folks on this forum to use system.debug to aid in understanding and in this case, the debug log itself is misleading

Eric
Visitor
amonkey
Posts: 4
0

Re: Database.getQueryLocator(String) truncates WHERE from Query String

[ Edited ]

What do you mean by system.debug, is that an aspect of the developer console. I am more familiar with the development directly in Sandbox. Also, when I run it I see way more rows returned than would be if the where clause were being used.

Visitor
amonkey
Posts: 4
0

Re: Database.getQueryLocator(String) truncates WHERE from Query String

Using the Query Editor on the developers console I was able to debug the issues I was having. You were correct about the debug logs being erroneous, my issue also arose from a mistake I had made in the where clause.

Trusted Contributor
crop1645
Posts: 359
0

Re: Database.getQueryLocator(String) truncates WHERE from Query String

you are welcome; pls mark as 'solved'

Eric