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
Danielle HensleyDanielle Hensley 

How to set up email automation without an object or condition?

Raj VakatiRaj Vakati
You can do it by using this ways 
  1. Apex Scheduler 
  2. Batch apex 

global class ApexScheduledClass Implements Schedulable
            {
                        global void execute(SchedulableContext sc)
                        {
                                    sendmail();
                        }
 
                        public void sendmail()
                        {// Please add your logic according to requirement
                                    Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
                                    string [] toaddress= New string[]{'demo@gmail.com'};
                                    email.setSubject('Testing Apex Scheduler-Subject');
                                    email.setPlainTextBody('Testing Apex Scheduler-Body');
                                    email.setToAddresses(toaddress);
                                    Messaging.sendEmail(New Messaging.SingleEmailMessage[]{email});
                        }
            }

Or like below
 
global class InactiveApplication implements Database.Batchable<sObject>
{
    global Database.QueryLocator start(Database.BatchableContext BC)
    {
        String query = 'Select Id, Name, Owner.Email from Trade_Ally_Account__c where Stage__c = 'Prospecting' and LastModifiedDate = LAST_N_DAYS:31';
        return Database.getQueryLocator(query);
    }
 
    global void execute(Database.BatchableContext BC, List<Trade_Ally_Account__c> scope)
    {       
        EmailTemplate emailTemplate = [select Id, Body from EmailTemplate where DeveloperName = 'Update_Service_Request'];
        
        for(Trade_Ally_Account__c ta : (List<Trade_Ally_Account__c>)scope) {
            Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
            email.setToAddresses(new String[] {ta.Owner.Email});
            email.setSaveAsActivity(false);
            email.setTargetObjectId(ta.OwnerId);
            email.setTemplateId(emailTemplate.Id);
            email.setWhatId(ta.Id);
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
        }
    }  
    global void finish(Database.BatchableContext BC)
    {
    }
}

​​​​​​​
Danielle HensleyDanielle Hensley
Can we set up a phone call to walk through how to implement this? Thanks, Danielle Hensley Office Administrator Office: +1-843-329-7816 dhensley@phishlabs.com