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
deva nalisettideva nalisetti 

hi all,i got this First error: expecting a colon, found 'closedwon' type plese help on this.

global class batch_example implements Database.Batchable<sobject> {
    global Database.QueryLocator start (Database.BatchableContext bc){
       return Database.getQueryLocator('select id,closeDate,StageName from Opportunity where StageName!=:closed Won'); 
    } 
    global void execute(Database.BatchableContext bc,list<opportunity>scope){
        for(opportunity op:scope){
            op.closeDate=system.today();
        }
        update scope;
    }
    global void finish (Database.batchableContext bc){
        Messaging.SingleEmailMessage email1=new Messaging.SingleEmailMessage();
        string[]toadd=new string[]{'ora0423.nallisetti@gmail.com'};
            email1.setToAddresses(toadd);
        email1.setSubject('batch completion Alert');
        email1.setplainTextBody('Batch job'+bc.getJobId()+ 'is processed successfully');
        Messaging.Email[]emails=new Messaging.Email[]{email1} ;
          Messaging.sendEmail(emails);
    
    }
}
Sagar PatilSagar Patil
Hi Deva,

I tried to save above code which you have posted in Salesforce instance and I haven't received any compile error. Can you please save this code and check if you get any error.

Kindly mark this as best answer if it helps you. 

Regards,
Sagar
mukesh guptamukesh gupta
Hi Deva,

In SOQL you are using 'closed Won' that's using as a list , but you have not decleare this list and also not fill up value , so it's shwoing error not found.

Please let me know if you have any assistanse..

Kindly mark my solution as the best answer if it helps you.




Thanks
Mukesh
 
Dhirendra verma 18Dhirendra verma 18
Hi Deva , 
The query you have used in inappropriate. The closed won should be within single quotes . Please try with the below query.
Database.getQueryLocator('select id,closeDate,StageName from Opportunity where StageName != \'closed Won\'').

Thanks, 
Dhirendra