Advertisement
YuraSidorets

Untitled

Aug 4th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. global class HandleBooksBatchableClass implements Database.Batchable<SObject> {
  2.  
  3. global HandleBooksBatchableClass() {
  4.  
  5. }
  6.  
  7. /**
  8. * @description gets invoked when the batch job starts
  9. * @param context contains the job ID
  10. * @returns the record set as a QueryLocator object that will be batched for execution
  11. */
  12. global Database.QueryLocator start(Database.BatchableContext context) {
  13. return Database.getQueryLocator('SELECT Id, Name, Author__c FROM Book__c WHERE Author__c != null');
  14. }
  15.  
  16. /**
  17. * @description gets invoked when the batch job executes and operates on one batch of records. Contains or calls the main execution logic for the batch job.
  18. * @param context contains the job ID
  19. * @param scope contains the batch of records to process.
  20. */
  21. global void execute(Database.BatchableContext context, List<Book__c> scope) {
  22. Map<id, Book__c> books = new Map<id, Book__c>(scope);
  23.  
  24. Map<id, BooksToWriters__c> booksWithWriters = new Map<id, BooksToWriters__c>([Select Id, Book__c From BooksToWriters__c WHERE Book__c in books.values()]);
  25.  
  26. for(BooksToWriters__c bookExists :booksWithWriters){
  27. books.remove(bookExists.Book__c.Id);
  28. }
  29.  
  30.  
  31. Set<string> writersNames = new Set<string>();
  32. for(Book__c bookAuthor : books.values()){
  33. writersNames = bookAuthor.Author;
  34. }
  35. List<Writer__c> writers = [Select id, Name From Writer__c Where Name IN :writersNames];
  36.  
  37. Map<Book__c, Writer__c> booksAndAuthors = new Map<Book__c, Writer__c> ();
  38. for(
  39.  
  40.  
  41.  
  42. List<BooksToWriters__c> newBooksToWriters = new List<BooksToWriters__c>();
  43.  
  44. for(Book__c bookToSetAuthor : books.values()){
  45. newBooksToWriters.add(new BooksToWriters__c(Book__c = bookToSetAuthor, Writer__c = ));
  46. }
  47. }
  48.  
  49. /**
  50. * @description gets invoked when the batch job finishes. Place any clean up code in this method.
  51. * @param context contains the job ID
  52. */
  53. global void finish(Database.BatchableContext context) {
  54.  
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement