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
sumit dsumit d 

Making class invocable to run a schedulable class

Hi All,
           I have a schedulable class, I want ot call it from another class and make the second class invocable. how can i do this?
My class and invocable class is given below:-

global  class SendEmailToKnowledgeArticleFollower implements Schedulable {

    global void execute(SchedulableContext sc)
    public Static void SendEmail() {
        Set<Id> knowledgeArticleIdSet = new Set<Id>();
        Map<Id,Knowledge__kav> mapOfKnowledgeArticleVersion = new  Map<Id,Knowledge__kav>();
        List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
        EmailTemplate et = [SELECT Id,Subject, Body FROM EmailTemplate WHERE DeveloperName = 'KnowledgeArticlePublished'];
        List<Knowledge__kav> knowledgeArticlesPublishedToday =  [SELECT Id,LastPublishedDate,PublishStatus,KnowledgeArticleId,IsLatestVersion,Title  
                                                                FROM Knowledge__kav 
                                                                WHERE LastPublishedDate  = TODAY ];
        if (!knowledgeArticlesPublishedToday.isEmpty()) {
            for (Knowledge__kav kav : knowledgeArticlesPublishedToday) {

            List<EntitySubscription> knowledgeArticleFolower = [SELECT  ID, ParentId, SubscriberId,Subscriber.Name,Subscriber.Email   
                                                                FROM EntitySubscription 
                                                                WHERE ParentId 
                                                                IN :knowledgeArticleIdSet];
            if (!knowledgeArticleFolower.isEmpty()) {
                OrgWideEmailAddress orgWideAddress = [SELECT Id, Address, DisplayName 
                                                              FROM OrgWideEmailAddress 
                                                              WHERE Address='' 
                                                              LIMIT 1 ];
                for (EntitySubscription follower : knowledgeArticleFolower) {
                    List<String> sendTo = new List<String>();
                    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                    Messaging.SingleEmailMessage getEmailTempResponse = Messaging.renderStoredEmailTemplate(et.Id, follower.SubscriberId, mapOfKnowledgeArticleVersion.get(follower.ParentId).Id);
                    // Set email contents - you can use variables!
                    if ( orgWideAddress != null) {
                        mail.setOrgWideEmailAddressId( orgWideAddress.Id );
                        // mail.setSenderDisplayName(orgWideAddress.DisplayName);

Invocable class is given below:- 
public class InvocableSendEmailToFollowers {
    public static void SendEmailToFollower( List<Id> articleIds ) {
     List<Knowledge__kav> knowledgeArticlesPublishedToday =  [SELECT Id,LastPublishedDate,PublishStatus,KnowledgeArticleId,IsLatestVersion,Title  
                                                                FROM Knowledge__kav 
                                                                WHERE LastPublishedDate  = TODAY AND Id IN: articleIds ];
here i want that when i will call a flow from button after clicking of button flow will call the invocable and do the rest thing.
Can anyone help me with this?
PriyaPriya (Salesforce Developers) 
Hi Sumit,

You can create apex action to call the ivocable method.And you can create a Button Invoke Method to call the flow.

Please refer below link

Hope this is helpful!