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
Jonathan Wolff 7Jonathan Wolff 7 

Apex Scheduler for my Apex class

Hello, I have an apex class that should be automatically scheduled to be executed at the last day of the month. Could you tell me how to edit my Apex class code to add the scheduler code? I really do not understand how to combine these 2 codes. My Apex class:
 
public class GeneratePDF{
   
@InvocableMethod(Label = 'PDF genreation' description='')
public static void generatePDF(List<Id> AccountId) {

     PageReference page = Page.MonthlyReport;

    
     page.getParameters().put('Id', AccountId.get(0));
     Blob contentBlob = page.getContentAsPDF();
     
    ContentVersion cv = new ContentVersion();
    cv.VersionData = contentBlob;
    cv.Title = 'MonthlyReport Pdf';
    cv.PathOnClient = 'MonthlyReport.pdf' ;
    insert cv;                
    cv = [SELECT Id, ContentDocumentId FROM ContentVersion WHERE Id = :cv.Id LIMIT 1];
        
    ContentDocumentLink cdl = new ContentDocumentLink();
    cdl.ContentDocumentId = cv.ContentDocumentId;
    cdl.ShareType = 'I';
    cdl.LinkedEntityId = AccountId.get(0);
    insert cdl;
    }
}

 
MagulanDuraipandianMagulanDuraipandian
Jonathan,
You can call GeneratePDF.generatePDF(list of ids) from your scheduled apex.

--
Magulan Duraipandian
www.infallibletechie.com