Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- global class HandleBooksBatchableClass implements Database.Batchable<SObject> {
- global HandleBooksBatchableClass() {
- }
- /**
- * @description gets invoked when the batch job starts
- * @param context contains the job ID
- * @returns the record set as a QueryLocator object that will be batched for execution
- */
- global Database.QueryLocator start(Database.BatchableContext context) {
- return Database.getQueryLocator('SELECT Id, Name, Author__c FROM Book__c WHERE Author__c != null');
- }
- /**
- * @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.
- * @param context contains the job ID
- * @param scope contains the batch of records to process.
- */
- global void execute(Database.BatchableContext context, List<Book__c> scope) {
- Map<id, Book__c> books = new Map<id, Book__c>(scope);
- Map<id, BooksToWriters__c> booksWithWriters = new Map<id, BooksToWriters__c>([Select Id, Book__c From BooksToWriters__c WHERE Book__c in books.values()]);
- for(BooksToWriters__c bookExists :booksWithWriters){
- books.remove(bookExists.Book__c.Id);
- }
- Set<string> writersNames = new Set<string>();
- for(Book__c bookAuthor : books.values()){
- writersNames = bookAuthor.Author;
- }
- List<Writer__c> writers = [Select id, Name From Writer__c Where Name IN :writersNames];
- Map<Book__c, Writer__c> booksAndAuthors = new Map<Book__c, Writer__c> ();
- for(
- List<BooksToWriters__c> newBooksToWriters = new List<BooksToWriters__c>();
- for(Book__c bookToSetAuthor : books.values()){
- newBooksToWriters.add(new BooksToWriters__c(Book__c = bookToSetAuthor, Writer__c = ));
- }
- }
- /**
- * @description gets invoked when the batch job finishes. Place any clean up code in this method.
- * @param context contains the job ID
- */
- global void finish(Database.BatchableContext context) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement