You need to sign in to do that
Don't have an account?
sai kumar 433
can uplz execute this code?
global class OpportunityBatch implements database.batchable<sObject>{ global String opptyList;
global Database.QueryLocator start(Database.BatchableContext info){ String status = ‘Submitted’;
List<Opportunity> opptyList = ‘select name,AccountName__c from Opportunity where status__c =\”+ status +’\” ;
return Database.getQueryLocator(opptyList);
}
global void execute(Database.batchableContext info,List<Opportunity> opptyList){ List<Opportunity> opportunitiesList = new List< Opportunity >();
for(Opportunity oppty: opptyList){ oppty.status__c = ‘Approved’; opportunitiesList.add(oppty);
}
Insert opportunitiesList;
}
global void finish(Database.batchableContext info){
}
global Database.QueryLocator start(Database.BatchableContext info){ String status = ‘Submitted’;
List<Opportunity> opptyList = ‘select name,AccountName__c from Opportunity where status__c =\”+ status +’\” ;
return Database.getQueryLocator(opptyList);
}
global void execute(Database.batchableContext info,List<Opportunity> opptyList){ List<Opportunity> opportunitiesList = new List< Opportunity >();
for(Opportunity oppty: opptyList){ oppty.status__c = ‘Approved’; opportunitiesList.add(oppty);
}
Insert opportunitiesList;
}
global void finish(Database.batchableContext info){
}
Hi Sai,
Hope you are getting comile time error for this code..
1- You have a silly mistake in the code that you are trying to initialize a string to list of opportunity.Make a corredction to the line: List<Opportunity> opptyList = ‘select name,AccountName__c from Opportunity where status__c =\”+ status +’\” ;
to String opptyList = ‘select name,AccountName__c from Opportunity where status__c =\”+ status +’\” ;
Hope this helped.... :)
Try with below code ,What I think you need to update the opportunity not insert and have some issue in query string which I have modified ,please check . Thanks
Manoj
Please check the below code snippet for your requirement which works perfectly in my org. Try to create some custom fields on the object(Account name and status) and then try the below code.
Batch Class :
How to call the above batch class :
Please mark my solution as the best answer if helps you...........
Best Regards,
Nagendra.P