Advertisement
Guest User

Untitled

a guest
Feb 24th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. global Database.QueryLocator start(Database.BatchableContext BC){
  2. //String query = 'Select Id FROM Call_Plan_Scenario__c LIMIT 2';
  3. String fieldsreturned;
  4. str=Utilities.GetHeaders(db_ObjectName)+'rn';
  5. string[] fields=Utilities.GetQuery(db_ObjectName );
  6. String query = 'select '+ String.join(fields, ',') +' from '+ db_ObjectName;
  7. return database.getQueryLocator(query);
  8. }
  9.  
  10. global void execute(Database.BatchableContext BC, List<sobject> scope){
  11. for(sObject rec : scope){
  12. str+=Utilities.GetRecord(rec,db_ObjectName);
  13. system.debug('**str**'+str);
  14. //str+='|'+'n';
  15. }
  16. }
  17.  
  18. global void finish(Database.BatchableContext BC){
  19. system.debug('**str**'+str);
  20. string nameOfFile = db_ObjectName;
  21. nameOfFile = nameOfFile.substring(0,nameOfFile.length()-3);
  22. system.debug(nameOfFile);
  23.  
  24. Transient Attachment myAttachment = new Attachment();
  25. myAttachment.Body = Blob.valueOf(str);
  26. myAttachment.Name = nameOfFile +'.txt';
  27. myAttachment.ParentId = callPlanScenario.Id;
  28. myAttachment.ContentType = 'text/csv';
  29.  
  30. insert myAttachment;
  31. AsyncApexJob a = [SELECT Id, Status, NumberOfErrors, JobItemsProcessed, TotalJobItems, CreatedBy.Email FROM AsyncApexJob WHERE Id =:BC.getJobId()];
  32. if(a.NumberOfErrors ==0){
  33. // Database.executeBatch(new DeleteRecordsBatch(callPlanScenario,db_ObjectName,counter),1500);
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement