function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Robert WamboldRobert Wambold 

How to get from Developer Console to APEX Class?

Hello All,

I got my code to work in the Developer Console but how to make it a schedulable APEX Class? Basically, my code should create a CSV file from TASK table based upon ActivityDate. For the life of me I cannot fiqure out to get my Developer Console code to schedulable APEX Class.

Can anyone help?

With thanks in advnce.

Bob

Here's my code:


DateTime Extract_date = system.now();
String FormattedExtract_date=Extract_date.format('MM/dd/yyyy');
DateTime Deletable_date = system.now().addDays(-1065);
String FormattedDeletable_date=Deletable_date.format('MM/dd/yyyy');
String MyFileName='Task Extract ' + FormattedExtract_date + ' for Activity thru ' + FormattedDeletable_date + '.csv';

String csv = 'AccountId, ActivityDate, Activity_Cost__c, Associated_Campaign__c, CallDisposition, CallDurationInSeconds, CallObject, CallType, Call_Notes__c, Call_Type__c, Call_SubType__c, CreatedById, CreatedDate, Description, Disposition__c, Go_Forward_Secured__c, Id, IsArchived, IsClosed, IsDeleted, IsHighPriority, IsRecurrence, IsReminderSet, LastModifiedById, LastModifiedDate, Next_Go_Forward_Date__c, Next_Go_Forward_Goal__c, OwnerId, Planned__c, Priority, RecurrenceActivityId, RecurrenceDayOfMonth, RecurrenceDayOfWeekMask, RecurrenceEndDateOnly, RecurrenceInstance, RecurrenceInterval, RecurrenceMonthOfYear, RecurrenceRegeneratedType, RecurrenceStartDateOnly, RecurrenceTimeZoneSidKey, RecurrenceType, ReminderDateTime, SystemModstamp, Type, User_Days_Worked__c, WhatCount,    WhatId, WhoCount, WhoId, Status, Subject, TaskSubtype\n';

for ( List<Task> tasks : [ SELECT AccountId, ActivityDate, Activity_Cost__c, Associated_Campaign__c, CallDisposition, CallDurationInSeconds, CallObject, 
CallType, Call_Notes__c, Call_Type__c, Call_SubType__c, CreatedById, CreatedDate, Description, Disposition__c, Go_Forward_Secured__c, Id, IsArchived, IsClosed, IsDeleted, IsHighPriority,
IsRecurrence, IsReminderSet, LastModifiedById, LastModifiedDate, Next_Go_Forward_Date__c, Next_Go_Forward_Goal__c, OwnerId, Planned__c, Priority,
RecurrenceActivityId, RecurrenceDayOfMonth, RecurrenceDayOfWeekMask, RecurrenceEndDateOnly, RecurrenceInstance, RecurrenceInterval, RecurrenceMonthOfYear,    
RecurrenceRegeneratedType, RecurrenceStartDateOnly, RecurrenceTimeZoneSidKey, RecurrenceType, ReminderDateTime, SystemModstamp, Type,
User_Days_Worked__c, WhatCount,    WhatId, WhoCount, WhoId,
Status, Subject, TaskSubtype 
FROM Task
Where Deletable__c = TRUE] )
{
 for ( Task T : tasks )
 {
  csv +=
   T.AccountId + ',' + T.ActivityDate + ',' + T.Activity_Cost__c + ',' + T.Associated_Campaign__c + ',' + T.CallDisposition + ',' + T.CallDurationInSeconds + ',' + 
   T.CallObject + ',' + T.CallType    + ',' + T.Call_Notes__c + ',' + T.Call_Type__c + ',' + T.Call_SubType__c + ',' + T.CreatedById + ',' + T.CreatedDate + ',' +
   T.Description + ',' + T.Disposition__c + ',' + T.Go_Forward_Secured__c + ',' + T.Id + ',' + T.IsArchived + ',' + T.IsClosed + ',' + T.IsDeleted + ',' + T.IsHighPriority + ',' +
   T.IsRecurrence + ',' + T.IsReminderSet + ',' + T.LastModifiedById + ',' + T.LastModifiedDate + ',' + T.Next_Go_Forward_Date__c + ',' + T.Next_Go_Forward_Goal__c + ',' +
   T.OwnerId + ',' + T.Planned__c + ',' + T.Priority + ',' + T.RecurrenceActivityId + ',' + T.RecurrenceDayOfMonth + ',' + T.RecurrenceDayOfWeekMask + ',' +
   T.RecurrenceEndDateOnly + ',' + T.RecurrenceInstance + ',' + T.RecurrenceInterval + ',' + T.RecurrenceMonthOfYear + ',' + T.RecurrenceRegeneratedType + ',' +    
   T.RecurrenceStartDateOnly + ',' + T.RecurrenceTimeZoneSidKey + ',' + T.RecurrenceType + ',' + T.ReminderDateTime + ',' + T.SystemModstamp + ',' + T.Type + ',' +
   T.User_Days_Worked__c + ',' + T.WhatCount + ',' + T.WhatId + ',' + T.WhoCount + ',' + T.WhoId + ',' +    
   T.Status + ',' + T.Subject + ',' + 
  T.TaskSubtype.escapeCsv() + '\n';
 }
}

ContentVersion file = new ContentVersion
(
      title = MyFileName,
      versionData = Blob.valueOf( csv ),
      pathOnClient = '/Task Extract 2018-08-16.csv'
);

insert file;
System.debug( file );

 

 

 

Naveen IlaNaveen Ila
Hi Robert, 

You can find the documentation on how to create Schedule Apex class here (https://developer.salesforce.com/docs/atlas.en-us.214.0.apexcode.meta/apexcode/apex_scheduler.htm" target="_blank). 


Still you are facing any issue let me know.