• SF_SAK
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies

Hello All,

I am getting 

Error: Compile Error: Expression cannot be assigned at line -1 column -1

global class UpdateAllOpportunities implements Database.Batchable<sObject> { 
// This is the query that is passed to the execute method. 
// It queries all of the Opportunities with specific criteria Pipeline
String query = 'Select Id,OwnerId FROM Opportunity WHERE (StageName != Sold OR StageName != Not Sold) AND Revenue__c > 500000';

global database.queryLocator start(Database.BatchableContext BC) {
return database.getQueryLocator(query); 

} //close start method 

global void execute(Database.BatchableContext BC, list <Opportunity> scope) {
List<Task> taskList = new List<Task>(); 
// Iterate through the whole query of Opportunities and create tasks requesting update 
// Create a Task that's associated with each Opportunity. 
for(Opportunity o : scope) { 
Task tsk = new Task(); 
tsk.OwnerId = o.OwnerId; 
tsk.ActivityDate = System.today()+ 3; 
tsk.Status = 'Not Started'; 
tsk.Subject = 'Weekly Opportunity Update Reminder';
task.description = 'Please update the task with work planned and completed for the week by Wednesday';
task.priority = 'High'; 
task.IsReminderSet = 'true';
task.ReminderDateTime = System.today()+1;
taskList.add(tsk);

} //close for-loop 
try {
insert taskList; 
} catch (system.dmlexception e) { 
System.debug('Tasks not inserted: ' + e); 

try {
update scope; 
} catch (system.dmlexception e) {
System.debug('Scope not updated: ' + e); 

} //close execute method 
global void finish(Database.BatchableContext BC) {
AsyncApexJob a = [Select Id, Status, NumberOfErrors, JobItemsProcessed,TotalJobItems,CreatedBy.Email from AsyncApexJob where Id = :BC.getJobId()];
// Create and send an email with the results of the batch.
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); 
mail.setToAddresses(new String[] {a.CreatedBy.Email}); 
mail.setReplyTo('Salesforce.NoReply@optum.com'); 
mail.setSenderDisplayName('Strategic Opportunity Task Creation Batch Processing');
mail.setSubject('Opportunity Task Creation Update ' + a.Status); 
mail.setPlainTextBody('The batch apex job processed ' + a.TotalJobItems + ' batches with ' + a.NumberofErrors + ' failures.'); 
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); 
} //close finish method 
} //close class

I am trying to create a batch apex to create tasks when Opportunity meets a specific criteria.

 

Also can someone tell me how I can set the notification flag to true in this code?

 

thanks for your help

SAK

 

  • February 25, 2013
  • Like
  • 0

Hello All,

I am getting 

Error: Compile Error: Expression cannot be assigned at line -1 column -1

global class UpdateAllOpportunities implements Database.Batchable<sObject> { 
// This is the query that is passed to the execute method. 
// It queries all of the Opportunities with specific criteria Pipeline
String query = 'Select Id,OwnerId FROM Opportunity WHERE (StageName != Sold OR StageName != Not Sold) AND Revenue__c > 500000';

global database.queryLocator start(Database.BatchableContext BC) {
return database.getQueryLocator(query); 

} //close start method 

global void execute(Database.BatchableContext BC, list <Opportunity> scope) {
List<Task> taskList = new List<Task>(); 
// Iterate through the whole query of Opportunities and create tasks requesting update 
// Create a Task that's associated with each Opportunity. 
for(Opportunity o : scope) { 
Task tsk = new Task(); 
tsk.OwnerId = o.OwnerId; 
tsk.ActivityDate = System.today()+ 3; 
tsk.Status = 'Not Started'; 
tsk.Subject = 'Weekly Opportunity Update Reminder';
task.description = 'Please update the task with work planned and completed for the week by Wednesday';
task.priority = 'High'; 
task.IsReminderSet = 'true';
task.ReminderDateTime = System.today()+1;
taskList.add(tsk);

} //close for-loop 
try {
insert taskList; 
} catch (system.dmlexception e) { 
System.debug('Tasks not inserted: ' + e); 

try {
update scope; 
} catch (system.dmlexception e) {
System.debug('Scope not updated: ' + e); 

} //close execute method 
global void finish(Database.BatchableContext BC) {
AsyncApexJob a = [Select Id, Status, NumberOfErrors, JobItemsProcessed,TotalJobItems,CreatedBy.Email from AsyncApexJob where Id = :BC.getJobId()];
// Create and send an email with the results of the batch.
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); 
mail.setToAddresses(new String[] {a.CreatedBy.Email}); 
mail.setReplyTo('Salesforce.NoReply@optum.com'); 
mail.setSenderDisplayName('Strategic Opportunity Task Creation Batch Processing');
mail.setSubject('Opportunity Task Creation Update ' + a.Status); 
mail.setPlainTextBody('The batch apex job processed ' + a.TotalJobItems + ' batches with ' + a.NumberofErrors + ' failures.'); 
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); 
} //close finish method 
} //close class

I am trying to create a batch apex to create tasks when Opportunity meets a specific criteria.

 

Also can someone tell me how I can set the notification flag to true in this code?

 

thanks for your help

SAK

 

  • February 25, 2013
  • Like
  • 0