+ Start a Discussion
Sumit  61Sumit 61 

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
  1. global class BatchOpportunitys implements Database.Batchable <sObject>{
  2.     
  3.     Id oppRecordTypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('New Rec Type').getRecordTypeId(); 
  4.     date dt4 = system.today();  
  5.      
  6.     global Database.QueryLocator start(Database.BatchableContext BC){
  7.         
  8.         
  9.         String query = 'SELECT Id,StageName FROM Opportunity RecordTypeId =:oppRecordTypeId AND StageName : Prospecting';
  10.         return Database.getQueryLocator(query);
  11.         
  12.     }
  13.     global void execute(Database.BatchableContext BC, List<Opportunity> scope){
  14.         
  15.         for(Opportunity opps : scope)
  16.          {   
  17.              System.debug('opps');
  18.              opps.StageName = 'Qualification';
  19.             opps.CloseDate = dt4;
  20.              opps.account.ownerId = opps.ownerId;
  21.              opps.account.Status__c = 'Lost';         
  22.          }
  23.          update scope;
  24.          System.debug('Record'+scope); 
  25.     }
  26.                
  27.             
  28.     global void finish(Database.BatchableContext BC){
  29.             
  30.     }
  31. }
Krishnamoorthi PeriasamyKrishnamoorthi Periasamy
It may be very silly question...did you schedule the batch job? Can i get debug log of last batch run?
Sumit  61Sumit 61
BatchOpportunitys  b = new BatchOpportunitys ();
Database.executeBatch(b);
Krishnamoorthi PeriasamyKrishnamoorthi Periasamy
so you did not schedule it, running thru Anonymous window....Ok, try this  

String query = 'SELECT Id,StageName FROM Opportunity where RecordTypeId =\'' + oppRecordTypeId + '\' AND StageName = \'Prospecting\'';
Krishnamoorthi PeriasamyKrishnamoorthi Periasamy

Try this...
String query = 'SELECT Id,StageName FROM Opportunity where RecordTypeId =\'' + oppRecordTypeId + '\' and StageName = \'Prospecting\'';
Krishnamoorthi PeriasamyKrishnamoorthi Periasamy
 global Database.QueryLocator start(Database.BatchableContext BC){
        
         
        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); 
    }
               
Krishnamoorthi PeriasamyKrishnamoorthi Periasamy
Did  abovet answer your question? If not, let me know what didn't work, or if so, please mark it solved. Thanks Krishna
Sumit  61Sumit 61
@Krishnamoorthi Periasamy Not Working
 
Krishnamoorthi PeriasamyKrishnamoorthi Periasamy
Can i know what is error ? Not working means ... is batch not executed? what is Apex job log info? please provide more information

Thanks
Krishna