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
MaggieSumitMaggieSumit 

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?
MaggieSumitMaggieSumit
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
MaggieSumitMaggieSumit
@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