Pregunta

I have to write a schedulebatch apex class on two objects

  1. Case
  2. Ticket__C

Ticket__c has a lookup to case and a case can have many ticket records but a ticket can only be associated to one case record

The Batch Apex class should run every morning at 2:00am and look at two fields(Status) in both the objects. Batch Apex shouls look at all the Cases and all the Tickets associated to the cases.

Case       -    Status (Field)
Ticket__c  -    GLOBAL_Ticket_Status__c (Field)

For example : if a case is associated with 3 Ticket__c records and the status of case is open, but status on 2 ticket__c records are closed and not the third record. Do not do anything. If status of all the Ticket__c records are set to closed for a particular Case record but the Case record status itself is still open, Close the case after 7 days of Ticket__c records status closed. (This is because if business want to add a ticket to that particular case they can just because the case status is not closed).

Any help in either how to initialize the objects and its fields or if anyone can write or guide me to write code will be much appreciated

¿Fue útil?

Solución

You may not need to make your code handle batches; it may be enough just to make it schedulable. It depends on how many SOQL queries or DML statements you need to get your work done. Remember, you can get many records with one SOQL query and save many records with one DML statement.

To make a class schedulable, you must either implement the Schedulable interface or call System.scheduleBatch. More details on making Apex schedulable here:

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_scheduler.htm

Here's a complete batch example that reassigns account owners:

http://developer.force.com/cookbook/recipe/using-batch-apex-to-reassign-account-owners

Here's an example of code that's schedulable and batchable too. It's a little more complex, but if you need to handle more records, you may find it necessary.

http://cloudforce4u.blogspot.com/2013/07/batch-apex-example.html

I hope these examples are useful to you.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top