• Scott Grabo
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 7
    Replies

I have a database.batchable class I've written, and can't seem to get the start() to execute correctly. I suspect it has something to do with the query itself.

 

I have a custom setting that is keeping track of the last time a given scheduled apex job has run. It's a simple datetime field. I want to use that in a query like this:

 

SELECT  ID, SomeField
  FROM  SomeObject
  WHERE SomeField IN ('This, That') AND
        LastModifiedDate > 2010-12-29T21:17:00 

Even though there's lots of documentation that seems to indicate this is the proper formatting, I'm getting "no viable alternative at character ' '" errors. In Eclipse, it rejects the colons, so I'm assuming this is the problem.

 

So I have two questions.

 

Question 1: What is the correct way to format dates for querying? Does it always require an assignment to the variable, so the query is rewritten as follows:

 

SELECT  ID, SomeField
  FROM  SomeObject
  WHERE SomeField IN ('This, That') AND
        LastModifiedDate> :someDateVariable

Question 2: If I do have to use a variable assignment within the query, and I make that variable part of the class and then assign the value in the calling routine, will the batch recognize that variable when executing the start()?

 

 

 

 

I have a database.batchable class I've written, and can't seem to get the start() to execute correctly. I suspect it has something to do with the query itself.

 

I have a custom setting that is keeping track of the last time a given scheduled apex job has run. It's a simple datetime field. I want to use that in a query like this:

 

SELECT  ID, SomeField
  FROM  SomeObject
  WHERE SomeField IN ('This, That') AND
        LastModifiedDate > 2010-12-29T21:17:00 

Even though there's lots of documentation that seems to indicate this is the proper formatting, I'm getting "no viable alternative at character ' '" errors. In Eclipse, it rejects the colons, so I'm assuming this is the problem.

 

So I have two questions.

 

Question 1: What is the correct way to format dates for querying? Does it always require an assignment to the variable, so the query is rewritten as follows:

 

SELECT  ID, SomeField
  FROM  SomeObject
  WHERE SomeField IN ('This, That') AND
        LastModifiedDate> :someDateVariable

Question 2: If I do have to use a variable assignment within the query, and I make that variable part of the class and then assign the value in the calling routine, will the batch recognize that variable when executing the start()?

 

 

 

 

Can someone confirm if this is expected behavior...?

 

I have a batch apex class that calculates a Contact's opportunity total and updates the contact record. It works fine, except I am seeing an odd error. This is an example of the SOQL I use, where ctotal is the instance of the Batch Apex Class.

 

 

ctotal.query = 'Select Id, total__c,(Select OpportunityId, Opportunity.StageName, Opportunity.Date_Received__c, Opportunity.Amount from OpportunityContactRoles where Opportunity.StageName = \'Collected\' Order by Opportunity.CloseDate ASC) From Contact WHERE Id = \'0034000000U842kAAB\'';

 

 

The contact I am filtering for has one Opportunity that matches the SOQL criteria, and if I submit this SOQL via the system log, it correctly returns on record.

 

But when I execute this in the Batch Context, it is returning two rows. Looking into it further, I discovered the second record is a deleted record, which only appears if I use the ALL ROWS parameter in the system log.

 

Do I need to filter my batch apex to disregard deleted rows, or should I be setting some other paramter, or is this a bug?

 

Thanks