0

I have tried the below code but it is not working.It is showing error like 'variable does not exist:SBQQ__ExpirationDate__c' Can anyone help me in this.

public class Task2 implements Database.Batchable<Sobject>{
    public Database.QueryLocator start(Database.BatchableContext bc){
        String s='Select SBQQ__Opportunity2__r.Name, Owner.Name, SBQQ__ExpirationDate__c 
                  from SBQQ__Quote__c';
        return Database.getQueryLocator(s);
    }

    public void execute(Database.BatchableContext bc,List<SBQQ__Quote__c>qdata){
        for(SBQQ__Quote__c quo:qdata){
            if(SBQQ__ExpirationDate__c==Tomorrow){
                EmailTemplate emailTemplate = [select Id, Body 
                                               from EmailTemplate 
                                               where DeveloperName = 'Notification'];
                Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
                email.setToAddresses(quo.Owner.Email);
                email.setSaveAsActivity(false);
                email.setTargetObjectId(quo.OwnerId);email.setWhatId(quo.Id);
                email.setTemplateId(emailTemplate.Id);
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
            }
        }
    }
    
    public void finish(Database.BatchableContext BC){
    }
}
2
  • Welcome to StackExchange. Have you considered using a Scheduled Flow for this? Also, check the email deliverability setting on your sandbox (if you're on a sandbox). Sep 6, 2022 at 10:27
  • 2
    Welcome to Salesforce Stack Exchange (SFSE)! Please edit your question to add additional information: exactly how is it not working (e.g., exact error text, unexpected output or results)? (Please read the What topics can I ask about here? section of Help Center where, among other things, it says that your question should include, 'A specific, detailed description of the issue ("it doesn’t work" is not enough to allow the community to help).')
    – Moonpie
    Sep 6, 2022 at 10:52

2 Answers 2

0
 for(SBQQ__Quote__c quo:qdata){
            if(SBQQ__ExpirationDate__c==Tomorrow){
                EmailTemplate emailTemplate = [select Id, Body 

I think this should be

 for(SBQQ__Quote__c quo:qdata){
            if( quo.SBQQ__ExpirationDate__c==Tomorrow){
                EmailTemplate emailTemplate = [select Id, Body 

You are referencing the field without the item in your loop

Also wondering if your date comparison will work, maybe it would work better like this: quo.SBQQ__ExpirationDate__c == Date.today().addDays(+1)

0

I want to send an email alert to opportunity owner. I have written the below code. It didn't show any errors while executing.But I am able to get any emails.

public class Task implements Database.Batchable<Sobject>{
public Database.QueryLocator start(Database.BatchableContext bc){
    String s='Select SBQQ__Opportunity2__r.Name,Owner.Name,owner.email,SBQQ__ExpirationDate__c from SBQQ__Quote__c';
    return Database.getQueryLocator(s);
}
public void execute(Database.BatchableContext bc,List<SBQQ__Quote__c>qdata){
    Messaging.SingleEmailMessage[] emailList = new List<Messaging.SingleEmailMessage>();
    for(SBQQ__Quote__c quo:qdata){
        if(quo.SBQQ__ExpirationDate__c ==Date.today().addDays(+1)){
            EmailTemplate emailTemplate = [select Id, Body from EmailTemplate where DeveloperName = 'Notification'];
            Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
            email.setToAddresses(new String[]{quo.Owner.Email});
            email.setSaveAsActivity(false);
            email.setTargetObjectId(quo.OwnerId);email.setWhatId(quo.Id);
            email.setTemplateId(emailTemplate.Id);
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
        }
    }
    
    
}
public void finish(Database.BatchableContext BC){
    system.debug('job id for batch job is==>'+bc.getJobId());
    
}

}

Can anyone help me..

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .