You need to sign in to do that
Don't have an account?

Unable to run the apex batch code to renew opportunities before 30 days of close date
Hi,
I have written the below apex batch code to renew the oportunity before 30 days of close date. I'm unable to run the code. Can anyone help me with the below code.
I have written the below apex batch code to renew the oportunity before 30 days of close date. I'm unable to run the code. Can anyone help me with the below code.
global class UpdateOpportunity implements Database.Batchable<sObject>, Database.stateful{ string query; global Database.querylocator start(Database.BatchableContext bc){ Query = 'SELECT id, name, Amount__c, Man_Power_Amount__c,Stage__c ' + 'FROM Opportunity__c ' + 'WHERE CloseDate = CloseDate()-30'; return Database.getQueryLocator(query); } global void execute(Database.BatchableContext bc, List<Opportunity__c> scope){ List<Opportunity> opportunities = new List<Opportunity>(); for (Opportunity opp : Scope ) { if (opp.CloseDate <= opp.CloseDate - 30) { Opportunity renewal = new Opportunity(); renewal.AccountId = 'opp.AccountId'; renewal.Name = opp.Name + 'Renewal'; renewal.CloseDate = opp.CloseDate + 365; renewal.StageName = 'Open'; renewal.RecordType = 'Renewal'; renewal.OwnerId = opp.OwnerId; renewals.put(renewal.Id, renewal); } update p; } global void finish(Database.BatchableContext bc){ System.debug(recordsprocessed + '' ); AsyncApexJob job = [SELECT Id, Status, NumberOfErrors, JobItemsProcessed, TotalJobItems, CreatedBy.Email FROM AsyncApexJob WHERE Id = :bc.getJobId()]; EmailUtils.sendMessage(a, recordsProcessed); } } }
Update your batch with below code
All Answers
Update your batch with below code
I got the below compile errors when i tried to run the code
when i have removed the emailutils and recordtype, I was able to run my code successfully