You need to sign in to do that
Don't have an account?
MaggieSumit
getting no response on batch, I have written batch class for update account status as lost and account owner as opportunity owner if Opportunity stage equal to Prospecting,
This My Code
- global class BatchOpportunitys implements Database.Batchable <sObject>{
- Id oppRecordTypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('New Rec Type').getRecordTypeId();
- date dt4 = system.today();
- global Database.QueryLocator start(Database.BatchableContext BC){
- String query = 'SELECT Id,StageName FROM Opportunity RecordTypeId =:oppRecordTypeId AND StageName : Prospecting';
- return Database.getQueryLocator(query);
- }
- global void execute(Database.BatchableContext BC, List<Opportunity> scope){
- for(Opportunity opps : scope)
- {
- System.debug('opps');
- opps.StageName = 'Qualification';
- opps.CloseDate = dt4;
- opps.account.ownerId = opps.ownerId;
- opps.account.Status__c = 'Lost';
- }
- update scope;
- System.debug('Record'+scope);
- }
- global void finish(Database.BatchableContext BC){
- }
- }
Database.executeBatch(b);
String query = 'SELECT Id,StageName FROM Opportunity where RecordTypeId =\'' + oppRecordTypeId + '\' AND StageName = \'Prospecting\'';
Try this...
String query = 'SELECT Id,StageName FROM Opportunity where RecordTypeId =\'' + oppRecordTypeId + '\' and StageName = \'Prospecting\'';
String query = 'SELECT Id,StageName,account.ownerId,account.status__c,ownerId FROM Opportunity where RecordTypeId =\'' + oppRecordTypeId + '\' and StageName = \'Prospecting\'';
System.debug(query);
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Opportunity> scope){
for(Opportunity opps : scope)
{
System.debug('opps :' + opps);
opps.StageName = 'Qualification';
opps.CloseDate = dt4;
opps.account.ownerId = opps.ownerId;
opps.account.Status__c = 'Lost';
}
update scope;
System.debug('Record'+scope);
}
Thanks
Krishna