Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- global Database.QueryLocator start(Database.BatchableContext BC){
- //String query = 'Select Id FROM Call_Plan_Scenario__c LIMIT 2';
- String fieldsreturned;
- str=Utilities.GetHeaders(db_ObjectName)+'rn';
- string[] fields=Utilities.GetQuery(db_ObjectName );
- String query = 'select '+ String.join(fields, ',') +' from '+ db_ObjectName;
- return database.getQueryLocator(query);
- }
- global void execute(Database.BatchableContext BC, List<sobject> scope){
- for(sObject rec : scope){
- str+=Utilities.GetRecord(rec,db_ObjectName);
- system.debug('**str**'+str);
- //str+='|'+'n';
- }
- }
- global void finish(Database.BatchableContext BC){
- system.debug('**str**'+str);
- string nameOfFile = db_ObjectName;
- nameOfFile = nameOfFile.substring(0,nameOfFile.length()-3);
- system.debug(nameOfFile);
- Transient Attachment myAttachment = new Attachment();
- myAttachment.Body = Blob.valueOf(str);
- myAttachment.Name = nameOfFile +'.txt';
- myAttachment.ParentId = callPlanScenario.Id;
- myAttachment.ContentType = 'text/csv';
- insert myAttachment;
- AsyncApexJob a = [SELECT Id, Status, NumberOfErrors, JobItemsProcessed, TotalJobItems, CreatedBy.Email FROM AsyncApexJob WHERE Id =:BC.getJobId()];
- if(a.NumberOfErrors ==0){
- // Database.executeBatch(new DeleteRecordsBatch(callPlanScenario,db_ObjectName,counter),1500);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement