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
Mr. CooL....Mr. CooL.... 

send an Email to customer before 10 days of due date and if he/she not payment before 5 day also send a one more mail alert by useling flow .

DevidDevid

can use scheduled flow here. but there may be some cases that user updating field again and again. I am not sure if flow will cancel that scheduled email of update due date later to other date. 

Better to use batch class and batch should run every day nightly.

SwethaSwetha (Salesforce Developers) 
HI,
If you want to consider using batch class, you can make use of below code to get started

Note that I am assuming you would have Payment_Due_Date__c, Payment_Status__c as custom fields in your org
public class PaymentReminderBatch implements Database.Batchable<SObject>, Database.AllowsCallouts {
    
    public void execute(Database.BatchableContext context, List<SObject> scope) {
        List<Contact> contactsToUpdate = new List<Contact>();
        List<Messaging.SingleEmailMessage> emailsToSend = new List<Messaging.SingleEmailMessage>();
        Date currentDate = Date.today();
        
        for (Contact contact : [SELECT Id, Name, Email, Payment_Due_Date__c, Payment_Status__c FROM Contact WHERE Payment_Due_Date__c >= :currentDate AND Payment_Status__c = 'Due']) {
            // Check if payment is due within 10 days
            if (contact.Payment_Due_Date__c.addDays(-10) <= currentDate) {
                Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
                email.setToAddresses(new List<String>{contact.Email});
                email.setSubject('Payment Reminder for ' + contact.Name);
                email.setPlainTextBody('Dear ' + contact.Name + ',\n\nThis is a reminder that your payment is due on ' + contact.Payment_Due_Date__c.format() + '. Please make the payment as soon as possible to avoid any late fees or penalties.\n\nBest regards,\nPayment Reminder Team');
                emailsToSend.add(email);
                
                // Check if payment is not made within 5 days of due date
                if (contact.Payment_Due_Date__c.addDays(-5) <= currentDate) {
                    emailsToSend.add(email);
                }
            }
            
            contact.Payment_Status__c = 'Reminder Sent';
            contactsToUpdate.add(contact);
        }
        
        update contactsToUpdate;
        
        if (!emailsToSend.isEmpty()) {
            Messaging.sendEmail(emailsToSend);
        }
    }
    
    public Database.QueryLocator start(Database.BatchableContext context) {
        return Database.getQueryLocator([SELECT Id, Name, Email, Payment_Due_Date__c, Payment_Status__c FROM Contact WHERE Payment_Due_Date__c >= :Date.today() AND Payment_Status__c = 'Due']);
    }
    
    public void finish(Database.BatchableContext context) {
        // Any post-processing code goes here
    }
}

If this information helps, please mark the answer as best. Thank you